Repository navigation
fix(gql): Scope the event processor to the query - #8307
Merged
sentrivana merged 2 commits intoNov 18, 2026
Merged
Conversation
The event processor was added to the isolation scope on every execute() and never removed, so later unrelated events got the last query's request data, and more than 20 queries made the scope drop all of its processors. Add it to a forked scope instead. Also set contexts.response.type to "response" instead of the response dict itself. Fixes getsentry#8262
sentrivana
requested changes
Nov 17, 2026
sentrivana
left a comment
Collaborator
There was a problem hiding this comment.
Thank you, looks good to me, but please check out my comment on the tests.
Comment on lines
+378
to
+406
| def test_queries_do_not_remove_other_event_processors(sentry_init, capture_events): | ||
| """ | ||
| Running many queries must not fill up the isolation scope's event | ||
| processors, which would make the scope drop processors added by others. | ||
| """ | ||
| sentry_init(integrations=[GQLIntegration()]) | ||
| events = capture_events() | ||
|
|
||
| def add_tag(event, hint): | ||
| event.setdefault("tags", {})["other_processor"] = "ran" | ||
| return event | ||
|
|
||
| sentry_sdk.get_isolation_scope().add_event_processor(add_tag) | ||
|
|
||
| for _ in range(25): | ||
| _execute_mock_query({"data": {"example": "This is the example"}}) | ||
|
|
||
| sentry_sdk.capture_message("unrelated") | ||
|
|
||
| (event,) = events | ||
| assert event["tags"]["other_processor"] == "ran" | ||
|
|
||
|
|
||
| def test_response_context_type(sentry_init, capture_events): | ||
| sentry_init(integrations=[GQLIntegration()], send_default_pii=True) | ||
|
|
||
| event = _make_erroneous_query(capture_events, _execute_mock_query) | ||
|
|
||
| assert event["contexts"]["response"]["type"] == "response" |
Collaborator
There was a problem hiding this comment.
Remove these two tests please. The first one is just testing a side-effect of the previous incorrect behavior, which we're now already testing in test_event_processor_does_not_outlive_query. The second one doesn't warrant its own test case. Can we add the assertion (assert event["contexts"]["response"]["type"] == "response") to an existing test instead?
Contributor
Author
There was a problem hiding this comment.
Done in 8cbc64d: removed both tests and added the type assertion to test_real_gql_request_with_error_with_pii.
Drop the processor-count test, which only covered a side effect of the old behavior, and move the response type assertion into test_real_gql_request_with_error_with_pii.
sentrivana
marked this pull request as ready for review
November 18, 2026 10:44
sentrivana
enabled auto-merge (squash)
November 18, 2026 10:44
This was referenced Nov 19, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #8262
sentry_patched_executeadded its event processor to the isolation scope on everyClient.execute()and never removed it. Outside a per-request isolation scope (scripts, workers), or for many queries in one request, that meant:request.api_target: graphqland the last query attached;The processor is now added to a scope forked with
sentry_sdk.new_scope()aroundreal_execute, so it applies to events captured during the query (including theTransportQueryErrorevent) and is gone afterwards.This also fixes
contexts.response.type, which was set to the response dict itself and serialized as"<cyclic>". It is now"response".Tests:
test_event_processor_does_not_outlive_query: a message captured after a successful query has norequestorresponsedata.test_queries_do_not_remove_other_event_processors: a processor added to the isolation scope still runs after 25 queries.test_response_context_type:contexts.response.typeis"response".All three fail on master. The gql test module passes with gql 4.4.0 and 3.4.1.