Skip to content

feat: DataCollection now gates GraphQL error events, with separate document and variables options - #5934

Open
jamescrosswell wants to merge 11 commits into
ai/dc-5429-failed-request-0ffcbafrom
ai/dc-5432-graphql-5177a5
Open

jamescrosswell wants to merge 11 commits into
ai/dc-5429-failed-request-0ffcbafrom
ai/dc-5432-graphql-5177a5

Conversation

@jamescrosswell

@jamescrosswell jamescrosswell commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

Part of #5420 (Phase 2). Moves SentryGraphQLHttpFailedRequestHandler from SendDefaultPii to the resolved DataCollection categories. Without ConfigureDataCollection, every category falls back to SendDefaultPii, so bodies, headers and cookies come out as they do today. The exceptions are response cookies and the URL, both under "Worth flagging".

Stacked on #5935. Merge that first. This PR targets #5935's branch (ai/dc-5429-failed-request-0ffcba), so the diff shows only the GraphQL changes. #5935 adds the pieces both failed-request handlers share: the *WithLegacyPiiGate header accessors, GetSetCookies / CookieFilter.FilterSetCookieHeader, the behaviour-aware query, header and cookie filters, and the URL-credentials fix. Once #5935 is squash-merged, GitHub retargets this PR to main.

What each field reads now

Field Before Now
Request.Data (GraphQL request body) SendDefaultPii OutgoingRequestBody, then the query / variables members kept or removed by GraphQL.Document / GraphQL.Variables
Response.Data SendDefaultPii IncomingResponseBody
Request and response headers SendDefaultPii RequestHeadersWithLegacyPiiGate / ResponseHeadersWithLegacyPiiGate
Request.Cookies / Response.Cookies SendDefaultPii Cookies. Response cookies now come from Set-Cookie
Request.Url / Request.QueryString query always deny-list UrlQueryParams
Request.Url credentials and fragment kept when SendDefaultPii always dropped. The fragment goes to Request.Fragment when SendDefaultPii is on or DataCollection is configured

How the GraphQL categories combine with httpBodies

The handler attaches the raw HTTP request body, so that body is an outgoing request body first and a GraphQL document second. Both gates have to allow it:

  • OutgoingRequestBody decides whether any request body is attached.
  • Inside it, FilterRequestContent removes query when GraphQL.Document is off and variables when GraphQL.Variables is off. With both off it attaches nothing. Batched requests (a JSON array) are filtered per request. If a filter is needed and the body isn't a GraphQL request object, it is dropped instead of being sent unfiltered.

This matches sentry-java's Apollo interceptors, the client-side counterpart to this handler: isOutgoingRequestBody, then GraphqlUtils.filterRequestBody. Java's isGraphqlDocumentWithLegacyBodyGate() belongs to its server-side graphql-java reporter, which has no HTTP body. In .NET, GraphQLDocument / GraphQLVariables already fall back to SendDefaultPii, which is exactly what gated this body, so the resolver needs no new GraphQL accessor. Under the bridge, both gates are SendDefaultPii and the body comes through byte-for-byte as before. Unlike the JS SDK, the bridge maps SendDefaultPii = false to "GraphQL off", because this handler never attached the document without it.

The response body carries data and errors, not the document or variables, so only IncomingResponseBody gates it.

Worth flagging

Closes #5432

🤖 Generated with Claude Code

jamescrosswell and others added 5 commits November 16, 2026 13:43
The GraphQL failed-request handler now reads the resolved DataCollection
categories for the bodies it attaches, instead of SendDefaultPii:

- The request body is an outgoing request body, so it is attached only when
  OutgoingRequestBody is collected. Inside it, the `query` (document) and
  `variables` members are kept or removed according to GraphQLDocument and
  GraphQLVariables. Batched requests are filtered per request; a body that
  is not a GraphQL request object is dropped when filtering is needed.
- The response body is attached only when IncomingResponseBody is collected.

This mirrors sentry-java's Apollo interceptors. Without ConfigureDataCollection
every one of these categories falls back to SendDefaultPii, so the output is
unchanged. Headers, cookies and the URL stay on SendDefaultPii until the
shared accessors from #5429 land.

Refs #5432

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ollection

Uses the shared accessors from #5429, the same way SentryHttpFailedRequestHandler
does: headers go through RequestHeadersWithLegacyPiiGate and
ResponseHeadersWithLegacyPiiGate, cookies through Cookies, and Request.Url and
Request.QueryString through UrlQueryParams. Response cookies now come from
Set-Cookie, which responses send, rather than Cookie. Request.Url keeps the
same SendDefaultPii split for user:pass@ and #fragment as the HTTP handler.

Refs #5432

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Applies #5429's decision to the GraphQL handler verbatim: Request.Url always
drops userinfo and the fragment, whatever SendDefaultPii or DataCollection
say, and the fragment moves to SentryRequest.Fragment.

Refs #5432

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 77.61%. Comparing base (35f0f77) to head (32381f2).

Files with missing lines Patch % Lines
src/Sentry/GraphQLRequestContent.cs 97.29% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@                         Coverage Diff                          @@
##           ai/dc-5429-failed-request-0ffcba    #5934      +/-   ##
====================================================================
- Coverage                             77.75%   77.61%   -0.15%     
====================================================================
  Files                                   535      546      +11     
  Lines                                 19766    20128     +362     
  Branches                               3952     3989      +37     
====================================================================
+ Hits                                  15370    15623     +253     
- Misses                                 3544     3647     +103     
- Partials                                852      858       +6     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jamescrosswell
jamescrosswell changed the base branch from main to ai/dc-5429-failed-request-0ffcba November 16, 2026 03:29
jamescrosswell and others added 4 commits November 16, 2026 16:30
…or ConfigureDataCollection

Apply #5935's UrlFragmentWithLegacyPiiGate to the GraphQL failed-request
handler, which sets Request.Fragment itself.

Refs #5432

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jamescrosswell
jamescrosswell marked this pull request as ready for review November 17, 2026 22:56
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Nov 17, 2026

@sentry-junior sentry-junior Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good to approve, with optional comments

Closes #5432 as scoped: the GraphQL failed-request handler now reads every field from DataCollectionResolver, the legacy bridge keeps today's SendDefaultPii output, and GraphQL.Document / GraphQL.Variables filter the request body inside the OutgoingRequestBody gate. Tests cover the bridge, every document/variables combination, the body-type gates, batched bodies and malformed input.

  • Optional: GraphQL.Variables = false doesn't fully keep variable values out of the event. The exception message is errors[0].message (src/Sentry/SentryGraphQLHttpFailedRequestHandler.cs, around line 35), and Response.Data is gated only on IncomingResponseBody. Many servers echo bad variable values in error messages, for example graphql-js's Variable "$id" got invalid value .... This was already true before this PR. A sentence in the GraphQLOptions.Variables XML doc would set the right expectation.
  • Optional: when one GraphQL gate is off, FilterRequestContent (src/Sentry/GraphQLRequestContent.cs) drops any body that isn't a JSON object or array, such as multipart upload requests, and logs nothing. Dropping it is the safe default, but a LogDebug there would explain a missing Request.Data.
  • Optional: variable values that are collected are attached raw, without the key-based denylist in SensitiveDataFilter, so a variable named password is sent as-is. This matches the previous SendDefaultPii = true behaviour, so a follow-up is fine if scrubbing is wanted.

This is an automated preliminary review.

…riables doesn't cover

FilterRequestContent now logs at debug level when it drops a body it can't
filter, so a missing Request.Data has an explanation. The
GraphQLOptions.Variables doc notes that variable values echoed in server
error messages and response bodies aren't filtered.

Refs #5432

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@jamescrosswell

jamescrosswell commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator Author

Following up on the automated review:

  • Variables echoed in error messages and response bodies: not changed here, because by default this PR keeps today's output, and both have always been sent this way. The two cases differ:
    • Response body: handled as sentry-java handles it. It's attached only when IncomingResponseBody is on, because graphQL.variables covers the variables in the request, not what the server sends back. In 32381f2, the GraphQLOptions.Variables XML doc now says servers may echo variable values back, and that this option doesn't filter them.
    • Exception message: specific to .NET. It's the server's errors[0].message, and no DataCollection option covers it, whereas sentry-java builds its message from the operation name and type. Every fix changes the message users see, and so their issue titles, so it's tracked separately in GraphQL failed-request events use the server's error message, which can contain variable values #5968.
  • Bodies dropped without a log: fixed in 32381f2. FilterRequestContent now logs at debug level when it drops a body it can't filter, such as a multipart upload or invalid JSON, so a missing Request.Data has an explanation.
  • Filtering variable values by name: won't do. We're matching sentry-java, whose GraphqlUtils.filterRequestBody keeps or drops the whole variables member and doesn't filter values. The Data Collection spec also makes graphQL.variables a Boolean. Collected variables are sent as-is, as they were with SendDefaultPii = true.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DataCollection phase 2: migrate GraphQL instrumentation

1 participant