@@ -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 \n Post:{ 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 \n Post:{ 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