Skip to content

Commit 37d07f0

Browse files
ref(gql): Use new scopes API in GQL Integration (#2838)
1 parent ed27661 commit 37d07f0

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

sentry_sdk/integrations/gql.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
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+
38
from sentry_sdk.integrations import DidNotEnable, Integration
9+
from sentry_sdk.scope import Scope, should_send_default_pii
410

511
try:
612
import gql # type: ignore[import-not-found]
@@ -85,25 +91,22 @@ def _patch_execute():
8591
# type: () -> None
8692
real_execute = gql.Client.execute
8793

94+
@ensure_integration_enabled(GQLIntegration, real_execute)
8895
def sentry_patched_execute(self, document, *args, **kwargs):
8996
# 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))
9699

97100
try:
98101
return real_execute(self, document, *args, **kwargs)
99102
except TransportQueryError as e:
100103
event, hint = event_from_exception(
101104
e,
102-
client_options=hub.client.options if hub.client is not None else None,
105+
client_options=sentry_sdk.get_client().options,
103106
mechanism={"type": "gql", "handled": False},
104107
)
105108

106-
hub.capture_event(event, hint)
109+
sentry_sdk.capture_event(event, hint)
107110
raise e
108111

109112
gql.Client.execute = sentry_patched_execute
@@ -126,7 +129,7 @@ def processor(event, hint):
126129
}
127130
)
128131

129-
if _should_send_default_pii():
132+
if should_send_default_pii():
130133
request["data"] = _data_from_document(document)
131134
contexts = event.setdefault("contexts", {})
132135
response = contexts.setdefault("response", {})

0 commit comments

Comments
 (0)