Skip to content

Commit 77c7d8d

Browse files
committed
refactor: Replace deprecated configure_scope context manager with get_current_scope
Replaced the deprecated `configure_scope` context manager with `get_current_scope` for compatibility with sentry-sdk 2.42.0 [References from the migration guide](https://github.com/getsentry/sentry-python/blob/master/MIGRATION_GUIDE.md)
1 parent c656808 commit 77c7d8d

File tree

1 file changed

+32
-32
lines changed

1 file changed

+32
-32
lines changed

docker-app/qfieldcloud/core/utils2/sentry.py

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -24,35 +24,35 @@ def report_serialization_diff_to_sentry(
2424
bodystream: BytesIO buffer capturing the request's raw body.
2525
capture_message: bool used as a flag by the caller to create an extra event against Sentry to attach the files to.
2626
"""
27-
with sentry_sdk.configure_scope() as scope:
28-
try:
29-
logger.info("Sending explicit sentry report!")
30-
31-
filename = f"{name}_contents.txt"
32-
scope.add_attachment(
33-
bytes=bytes(
34-
f"Pre:\n{pre_serialization}\n\nPost:{post_serialization}",
35-
encoding="utf8",
36-
),
37-
filename=filename,
38-
)
39-
40-
filename = f"{name}_traceback.txt"
41-
scope.add_attachment(
42-
bytes=bytes(buffer.getvalue(), encoding="utf8"),
43-
filename=filename,
44-
)
45-
46-
if body_stream:
47-
filename = f"{name}_rawbody.txt"
48-
scope.add_attachment(bytes=body_stream.getvalue(), filename=filename)
49-
50-
if capture_message:
51-
sentry_sdk.capture_message("Explicit Sentry report!", scope=scope)
52-
53-
return True
54-
55-
except Exception as error:
56-
logger.error(f"Unable to send file to Sentry: failed on {error}")
57-
sentry_sdk.capture_exception(error)
58-
return False
27+
scope = sentry_sdk.get_current_scope()
28+
try:
29+
logger.info("Sending explicit sentry report!")
30+
31+
filename = f"{name}_contents.txt"
32+
scope.add_attachment(
33+
bytes=bytes(
34+
f"Pre:\n{pre_serialization}\n\nPost:{post_serialization}",
35+
encoding="utf8",
36+
),
37+
filename=filename,
38+
)
39+
40+
filename = f"{name}_traceback.txt"
41+
scope.add_attachment(
42+
bytes=bytes(buffer.getvalue(), encoding="utf8"),
43+
filename=filename,
44+
)
45+
46+
if body_stream:
47+
filename = f"{name}_rawbody.txt"
48+
scope.add_attachment(bytes=body_stream.getvalue(), filename=filename)
49+
50+
if capture_message:
51+
sentry_sdk.capture_message("Explicit Sentry report!", scope=scope)
52+
53+
return True
54+
55+
except Exception as error:
56+
logger.error(f"Unable to send file to Sentry: failed on {error}")
57+
sentry_sdk.capture_exception(error)
58+
return False

0 commit comments

Comments
 (0)