Skip to content

feat(gql): Gate GraphQL data collection behind data_collection option - #6889

Open
ericapisani wants to merge 4 commits into
masterfrom
py-2585-gql
Open

feat(gql): Gate GraphQL data collection behind data_collection option#6889
ericapisani wants to merge 4 commits into
masterfrom
py-2585-gql

Conversation

@ericapisani

@ericapisani ericapisani commented Jul 24, 2026

Copy link
Copy Markdown
Member

Attach the GraphQL document and variable definitions to error events based on the structured data_collection configuration (graphql.document / graphql.variables), falling back to send_default_pii when data_collection is not set.

Refs PY-2585
Refs #6745

…ption

The graphene integration now honors the experimental structured data_collection configuration when deciding whether to attach GraphQL-specific data. When data_collection is set, graphql.document controls whether request.api_target is marked as graphql on error events and whether the graphql.document attribute is attached to query/mutation spans (both streamed and transaction-embedded). When data_collection is not configured, behavior falls back to the existing send_default_pii gating, and data_collection takes precedence when both options are set.

Adds tests covering the new gating for the event processor and both span paths, including precedence over send_default_pii.
… option

Apply the data_collection option to the Strawberry integration so that

graphql.document, request data, and variables are only collected when

explicitly enabled. send_default_pii is used as a fallback only when

data_collection is not configured.

GraphQL operation names are now always captured when available,

independent of document or PII settings.
Attach the GraphQL document and variable definitions to error events based on the structured data_collection configuration (graphql.document / graphql.variables), falling back to send_default_pii when data_collection is not set.
@linear-code

linear-code Bot commented Jul 24, 2026

Copy link
Copy Markdown

PY-2585

@github-actions

github-actions Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Codecov Results 📊

99362 passed | ⏭️ 6806 skipped | Total: 106168 | Pass Rate: 93.59% | Execution Time: 359m 54s

📊 Comparison with Base Branch

Metric Change
Total Tests 📈 +131
Passed Tests 📈 +131
Failed Tests
Skipped Tests

All tests are passing successfully.

✅ Patch coverage is 100.00%. Project has 2570 uncovered lines.
✅ Project coverage is 89.55%. Comparing base (base) to head (head).

Files with missing lines (1)
File Patch % Lines
sentry_sdk/integrations/gql.py 100.00% ⚠️ 1 partials
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    89.54%    89.55%    +0.01%
==========================================
  Files          193       193         —
  Lines        24588     24603       +15
  Branches      8744      8756       +12
==========================================
+ Hits         22018     22033       +15
- Misses        2570      2570         —
- Partials      1408      1409        +1

Generated by Codecov Action

@ericapisani
ericapisani marked this pull request as ready for review July 28, 2026 18:00
@ericapisani
ericapisani requested a review from a team as a code owner July 28, 2026 18:00
response.update(
{
"data": {"errors": errors},
"type": response,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The response context dictionary is updated with a self-reference ("type": response), which will cause a ValueError during JSON serialization, preventing event capture.
Severity: CRITICAL

Suggested Fix

The value for the "type" key in the response context dictionary should be a string literal, such as "response", instead of the dictionary object itself. This will prevent the circular reference and allow the event to be serialized correctly.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: sentry_sdk/integrations/gql.py#L176

Potential issue: In the `processor` function, when GraphQL data collection is enabled
and an error occurs, the `response` context is updated with a self-referential key:
`response.update(..., "type": response)`. This creates a circular reference within the
dictionary. When the Sentry SDK attempts to serialize the event to JSON using
`json.dumps()`, it will encounter this circular reference and raise a `ValueError`,
causing the event capture to fail. This affects any user who enables the new GraphQL
document collection feature.

Also affects:

  • sentry_sdk/integrations/gql.py:180~183

Did we get this right? 👍 / 👎 to inform future reviews.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 058e048. Configure here.

else:
document = document_or_request

request["data"] = _data_from_document(document)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variables require document collection

Medium Severity

graphql.variables is only consulted inside _data_from_document, which runs only when graphql.document is enabled. With document off and variables on, variable data is never attached. The Strawberry integration and its tests treat these flags as independent under the same data_collection contract.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 058e048. Configure here.

Base automatically changed from py-2585-strawberry to master July 28, 2026 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants