@@ -138,21 +138,24 @@ def sentry_patched_execute(
138138 * args : "Any" ,
139139 ** kwargs : "Any" ,
140140 ) -> "Any" :
141- scope = sentry_sdk .get_isolation_scope ()
142- # document is a gql.GraphQLRequest with gql v4.0.0.
143- scope .add_event_processor (_make_gql_event_processor (self , document ))
144-
145- try :
141+ # Add the processor to a scope that lives only as long as this
142+ # query, so that it doesn't apply to unrelated events captured
143+ # later on the same isolation scope.
144+ with sentry_sdk .new_scope () as scope :
146145 # document is a gql.GraphQLRequest with gql v4.0.0.
147- return real_execute (self , document , * args , ** kwargs )
148- except TransportQueryError as e :
149- event , hint = event_from_exception (
150- e ,
151- mechanism = {"type" : "gql" , "handled" : False },
152- )
146+ scope .add_event_processor (_make_gql_event_processor (self , document ))
147+
148+ try :
149+ # document is a gql.GraphQLRequest with gql v4.0.0.
150+ return real_execute (self , document , * args , ** kwargs )
151+ except TransportQueryError as e :
152+ event , hint = event_from_exception (
153+ e ,
154+ mechanism = {"type" : "gql" , "handled" : False },
155+ )
153156
154- sentry_sdk .capture_event (event , hint )
155- raise e
157+ sentry_sdk .capture_event (event , hint )
158+ raise e
156159
157160 gql .Client .execute = sentry_patched_execute
158161
@@ -192,7 +195,7 @@ def processor(event: "Event", hint: "dict[str, Any]") -> "Event":
192195 response .update (
193196 {
194197 "data" : {"errors" : errors },
195- "type" : response ,
198+ "type" : " response" ,
196199 }
197200 )
198201
0 commit comments