Repository navigation
Description
How do you use Sentry?
Sentry Saas (sentry.io)
Version
master (860a060), gql 4.4.0
Steps to Reproduce
sentry_patched_execute adds an event processor to the isolation scope on every Client.execute() and never removes it:
scope = sentry_sdk.get_isolation_scope()
scope.add_event_processor(_make_gql_event_processor(self, document))gql is a client, so it's often called outside a per-request isolation scope (scripts, workers, task loops), or many times inside one request. The processors outlive the query and apply to every later event on that scope.
import sentry_sdk
from gql import Client, gql
from gql.transport.requests import RequestsHTTPTransport
from sentry_sdk.integrations.gql import GQLIntegration
sentry_sdk.init(dsn=..., integrations=[GQLIntegration()], send_default_pii=True)
client = Client(transport=RequestsHTTPTransport(url="http://example.com/graphql"))
for i in range(100):
client.execute(gql("query Q%d { example }" % i)) # all succeed
# later, unrelated to GraphQL
try:
raise ValueError("unrelated error")
except ValueError:
sentry_sdk.capture_exception()Full repro (HTTP mocked with responses, events captured from a custom transport): https://github.com/Mohil-Ahuja/ci-scratch/blob/main/repro/gql_processors.py, run output: https://github.com/Mohil-Ahuja/ci-scratch/actions/runs/42837565235
Expected Result
The unrelated ValueError has no GraphQL request data, and contexts.response.type is "response" on gql error events.
Actual Result
-
Unrelated errors are tagged as GraphQL requests. The
ValueErrorabove is sent with the last query attached:"request": {"api_target": "graphql", "method": "POST", "url": "http://example.com/graphql", "data": {"query": "query Q99 {\n example\n}", "variables": null, "operationName": "Q99"}}
-
Other processors on the scope get wiped. Once a scope has more than 20 processors,
Scope.add_event_processorclears all of them. So 21 gql calls in one request remove processors added by the app or other integrations. In the repro, a processor added to the same isolation scope before 21 queries is gone afterwards, and the next error event is missing its tag. -
contexts.response.typeis a self-reference. Both branches of the processor doresponse.update({"data": ..., "type": response}), which setstypeto the dict itself, so it's serialized as"<cyclic>":"response": {"data": {"errors": [{"message": "boom"}]}, "type": "<cyclic>"}
Possible fix: fork a scope around real_execute (with sentry_sdk.new_scope() as scope:) and add the processor there, so it only applies to events captured during the query (including the TransportQueryError event), and set "type": "response". Happy to open a PR with tests.
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsNo status
Activity
linear-code commentedon Nov 12, 2026
PY-3075
sentrivana commentedon Nov 17, 2026
Hey @Mohil-Ahuja, thanks for the report. Attaching the event processor to a temporary scope sounds like a good idea. Feel free to open a PR.
mohanprasath-dev commentedon Nov 17, 2026
Hi @Mohil-Ahuja
I'm interested in contributing to this issue and wanted to check whether you're currently working on the implementation or planning to submit a PR. I'd like to avoid duplicating any ongoing work.
@sentrivana , if this is not currently being pursued, would you be comfortable with me taking it forward?
My proposed approach is to attach the event processor to a temporary scope around real_execute(), ensuring that GraphQL error events retain their request context while unrelated events remain unaffected. I'd also address the response context type and add regression tests covering processor isolation, repeated executions, and error handling.
I'll hold off on implementation until I hear back.
Thanks!
Mohil-Ahuja commentedon Nov 17, 2026
Hi @mohanprasath-dev, thanks for checking. The fix is up in #8307 and is in review.
fix(gql): Scope the event processor to the query (getsentry#8307)