Skip to content

Commit

Permalink
ref(gql): Use new scopes API in GQL Integration (#2838)
Browse files Browse the repository at this point in the history
  • Loading branch information
szokeasaurusrex authored Mar 19, 2024
1 parent ed27661 commit 37d07f0
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions sentry_sdk/integrations/gql.py
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -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
Expand All @@ -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", {})
Expand Down

0 comments on commit 37d07f0

Please sign in to comment.