1
- from sentry_sdk .utils import event_from_exception , parse_version
2
- from sentry_sdk .hub import Hub , _should_send_default_pii
1
+ import sentry_sdk
2
+ from sentry_sdk .utils import (
3
+ event_from_exception ,
4
+ ensure_integration_enabled ,
5
+ parse_version ,
6
+ )
7
+
3
8
from sentry_sdk .integrations import DidNotEnable , Integration
9
+ from sentry_sdk .scope import Scope , should_send_default_pii
4
10
5
11
try :
6
12
import gql # type: ignore[import-not-found]
@@ -85,25 +91,22 @@ def _patch_execute():
85
91
# type: () -> None
86
92
real_execute = gql .Client .execute
87
93
94
+ @ensure_integration_enabled (GQLIntegration , real_execute )
88
95
def sentry_patched_execute (self , document , * args , ** kwargs ):
89
96
# type: (gql.Client, DocumentNode, Any, Any) -> Any
90
- hub = Hub .current
91
- if hub .get_integration (GQLIntegration ) is None :
92
- return real_execute (self , document , * args , ** kwargs )
93
-
94
- with Hub .current .configure_scope () as scope :
95
- scope .add_event_processor (_make_gql_event_processor (self , document ))
97
+ scope = Scope .get_isolation_scope ()
98
+ scope .add_event_processor (_make_gql_event_processor (self , document ))
96
99
97
100
try :
98
101
return real_execute (self , document , * args , ** kwargs )
99
102
except TransportQueryError as e :
100
103
event , hint = event_from_exception (
101
104
e ,
102
- client_options = hub . client .options if hub . client is not None else None ,
105
+ client_options = sentry_sdk . get_client () .options ,
103
106
mechanism = {"type" : "gql" , "handled" : False },
104
107
)
105
108
106
- hub .capture_event (event , hint )
109
+ sentry_sdk .capture_event (event , hint )
107
110
raise e
108
111
109
112
gql .Client .execute = sentry_patched_execute
@@ -126,7 +129,7 @@ def processor(event, hint):
126
129
}
127
130
)
128
131
129
- if _should_send_default_pii ():
132
+ if should_send_default_pii ():
130
133
request ["data" ] = _data_from_document (document )
131
134
contexts = event .setdefault ("contexts" , {})
132
135
response = contexts .setdefault ("response" , {})
0 commit comments