diff --git a/sentry_sdk/integrations/gql.py b/sentry_sdk/integrations/gql.py index 9db6632a4a..0552edde60 100644 --- a/sentry_sdk/integrations/gql.py +++ b/sentry_sdk/integrations/gql.py @@ -1,6 +1,12 @@ -from sentry_sdk.utils import event_from_exception, parse_version -from sentry_sdk.hub import Hub, _should_send_default_pii +import sentry_sdk +from sentry_sdk.utils import ( + event_from_exception, + ensure_integration_enabled, + parse_version, +) + from sentry_sdk.integrations import DidNotEnable, Integration +from sentry_sdk.scope import Scope, should_send_default_pii try: import gql # type: ignore[import-not-found] @@ -85,25 +91,22 @@ def _patch_execute(): # type: () -> None real_execute = gql.Client.execute + @ensure_integration_enabled(GQLIntegration, real_execute) def sentry_patched_execute(self, document, *args, **kwargs): # type: (gql.Client, DocumentNode, Any, Any) -> Any - hub = Hub.current - if hub.get_integration(GQLIntegration) is None: - return real_execute(self, document, *args, **kwargs) - - with Hub.current.configure_scope() as scope: - scope.add_event_processor(_make_gql_event_processor(self, document)) + scope = Scope.get_isolation_scope() + scope.add_event_processor(_make_gql_event_processor(self, document)) try: return real_execute(self, document, *args, **kwargs) except TransportQueryError as e: event, hint = event_from_exception( e, - client_options=hub.client.options if hub.client is not None else None, + client_options=sentry_sdk.get_client().options, mechanism={"type": "gql", "handled": False}, ) - hub.capture_event(event, hint) + sentry_sdk.capture_event(event, hint) raise e gql.Client.execute = sentry_patched_execute @@ -126,7 +129,7 @@ def processor(event, hint): } ) - if _should_send_default_pii(): + if should_send_default_pii(): request["data"] = _data_from_document(document) contexts = event.setdefault("contexts", {}) response = contexts.setdefault("response", {})