Skip to content

DataCollection phase 1: resolver and SendDefaultPii bridge #5426

Closed

Description

@jamescrosswell

Part of #5420. Phase 1 — foundation.

Add the internal resolved config and the legacy bridge; make it the single read path.

Note

The precedence below predates the non-nullable option shape landed in #5853; step 2 is now vacuous. See the resolution-model comment on this issue.

  • Internal resolved view (all fields populated), exposed internally (e.g. via SentryOptions).
  • Resolution precedence: (1) fields explicitly set on DataCollection; (2) if DataCollection is configured at all (ConfigureDataCollection called, or a value bound from configuration), missing fields use the new spec defaults (UserInfo=true, all HttpBodies, denyList behaviors); (3) if DataCollection is absent, derive everything from SendDefaultPii:
    • true → everything on.
    • false/unset → UserInfo=false, HttpBodies=None, GenAI off, DatabaseQueryData=false, deny-lists extended with GDPR terms (forwarded, -ip, remote-, via, -user).
  • If both DataCollection and SendDefaultPii are set, SendDefaultPii is ignored.
  • No consumer migrated yet — that happens per-area in Phase 2.

Decision: resolve-once vs. lazy per-call

The epic originally specified "resolve once at SDK init", copying JS (resolveDataCollectionOptions called in the Client constructor). sentry-java took the opposite approach: DataCollectionResolver holds a SentryOptions reference and recomputes on every query (isUserInfo(), getCookies(), …), with no cached snapshot.

Lazy is probably the better fit for .NET, because SentryOptions is a mutable object that callers can and do change after Init — a snapshot taken at init would silently ignore later edits, and options are also mutated in tests. The cost is recomputation per call, which matters on hot paths like header filtering, so consider caching the derived KeyValueCollectionBehavior values rather than the whole config.

Pick one explicitly here and note it in the epic; every Phase 2 issue reads through whatever this lands.

Legacy-gate variants may be needed per call site

sentry-java needed more than one accessor per category where integrations historically gated differently — e.g. isGraphqlDocument(), isGraphqlDocumentWithLegacyBodyGate(), isGraphqlDocumentWithLegacyAlways(). Expect the same in .NET (see #5432, where the GraphQL handler attaches the body only when SendDefaultPii is true, unlike JS). Design the resolver so a call site can ask for "resolved value, with this legacy fallback" instead of forcing one global bridge rule.

References: io.sentry.DataCollectionResolver (sentry-java 8.58.0); JS resolveDataCollectionOptions.ts / defaultPiiToCollectionOptions.ts (#20967, #20970).


Category list narrowed (2026-11-05). Mcp, Queues, FilePaths, StackFrameVariables and FrameContextLines were removed from DataCollectionOptions in #5853, as none has a consumer in the .NET SDK and the spec is still a candidate. See the deferred-categories note on #5420. This issue has been updated accordingly.

Activity

  1. linear-code commented on Jul 22, 2026

    @linear-code
  2. jamescrosswell commented on Nov 5, 2026

    @jamescrosswell
    CollaboratorAuthor

    The option shape this issue was written against has changed (2026-11-05). d18dd2ae4 in #5853 replaced the SentryOptions.DataCollection property with SentryOptions.ConfigureDataCollection(Action<DataCollectionOptions>), and every category on DataCollectionOptions is now non-nullable with the spec default as its initializer. Rationale in #5853 (comment).

    That simplifies the resolution precedence this issue specifies, so the three-step rule above should be read as two steps:

    1. options.DataCollection (now internal, still nullable) is null → nobody opted in → derive every category from SendDefaultPii, exactly as step 3 describes.
    2. It is non-null → read the object directly.

    Step 2 of the original rule — "if DataCollection is configured at all, missing fields use the new spec defaults" — is now vacuous. There are no missing fields: the defaults live on the object, which is handed to the callback already complete. The resolver only has to implement the SendDefaultPii derivation.

    Two consequences worth deciding here rather than in #5853:

    • Per-category fallback is not expressible any more. With no nullable categories there is no "unset" to fall back from, so opting in necessarily switches every category to the spec defaults at once. For an app on SendDefaultPii = false that calls the callback only to restrict cookies, user info and HTTP bodies go back on. That is accepted as intended — DataCollection is meant to replace SendDefaultPii, not layer over it — and is documented on ConfigureDataCollection. Flagging it because the resolver is where it becomes observable.
    • Configuration still opts in on section presence alone. An unbindable key such as DataCollection:Cookeis:Mode=Off creates the options with nothing set, which now reads as "opted in, spec defaults" — i.e. a typo makes the SDK collect more than SendDefaultPii = false did. The surrogate's own properties are all still nullable, so BindableSentryOptions.ApplyTo could instead create the options only when something actually bound. Not done in feat: add experimental DataCollection options, successor to SendDefaultPii #5853 because it changes behaviour for a section that binds nothing.
  3. jamescrosswell commented on Nov 5, 2026

    @jamescrosswell
    CollaboratorAuthor

    #5853 has merged (eef24b160), and two things changed after the comment above.

    1. KeyValueCollectionBehavior is now immutable. The public constructor and the Mode/Terms setters are gone; Off, DenyList(...) and AllowList(...) are the only ways to build one. Reason: terms only mean something next to their mode, so in-place editing let code and configuration combine into a behavior neither side wrote — config supplying Terms while code set Mode = AllowList produced AllowList[those terms], and code appending a deny term to a config-set allow list widened it instead. A category is now replaced whole, from either side.

    Two consequences for the resolver:

    • It has to produce behaviors, never mutate them in place.
    • The description's "consider caching the derived KeyValueCollectionBehavior values rather than the whole config" is now straightforward — instances are immutable, so one shared default instance can back every category with no aliasing risk. (That is also why the per-category independence test was deleted in this PR: it only meant something while they were mutable.)

    2. The XML docs now state that these options are inert, and this issue's PR has to delete that. sentry-warden flagged the docs as promising unimplemented behaviour — correct, since nothing in src/ reads DataCollection except ConfigureDataCollection creating it and BindableSentryOptions.ApplyTo writing it. The caveats to remove when the bridge lands:

    • SentryOptions.ConfigureDataCollection remarks — the opening paragraph ("The options are recorded but not yet consumed: no integration reads them, so what is collected is still governed entirely by SendDefaultPii, and restricting a category here has no effect yet"), and the paragraph after it, which states the SendDefaultPii replacement in the future tense conditional on migration. That becomes present tense.
    • DataCollectionOptions class remarks — the first line, "No integration reads these options yet, so setting a category has no effect on what is collected".

    If the bridge ships without touching these, the docs go stale in the misleading direction: they would understate what the SDK does.

    3. The configuration opt-in trigger is decided: section presence stays the opt-in. Raised on the PR, and the call was that DataCollection is new enough that nobody gets the section without adding it deliberately. Worth recording the evidence, because it is broader than the typo the comment above describes — three shapes all opt in while silently dropping the value, each verified against BindableSentryOptions.ApplyTo:

    Config Result
    DataCollection:Cookeis:Mode = Off (typo'd child key) opted in, Cookies at DenyList, UserInfo → true, HttpBodies → All
    "HttpBodies": [] same
    "Cookies": false same

    The third is not a typo: dataCollection.Cookies = false compiles in C# via the implicit bool conversion, so that is the natural translation into configuration, and the binder silently discards a scalar bound to a complex property. In all three the writer asked to restrict something and ended up opted in at permissive defaults with SendDefaultPii = false ignored — strictly more data than before.

    Documented rather than prevented, in the KeyValueCollectionBehavior and HttpBodies remarks. It becomes consequential once this issue makes the options live, so if it is revisited: requiring a bound value before opting in fixes rows 1 and 2 only; row 3 needs the surrogate to accept a scalar bool.

  4. jamescrosswell commented on Nov 5, 2026

    @jamescrosswell
    CollaboratorAuthor

    Decisions settled, implemented in #5885.

    Lazy, not resolve-once. DataCollectionResolver holds the SentryOptions and recomputes per query, as io.sentry.DataCollectionResolver does. A snapshot at Init would silently ignore the later edits that both applications and tests make to SentryOptions. The two default KeyValueCollectionBehavior instances are cached statics, which is safe now that #5853 made them immutable.

    The bridge does not extend deny lists with the GDPR terms, contrary to this issue's text — that part came from the JS bridge, and following it would have made the Phase 2 header migration carry a behaviour change.

    The .NET SDK has never filtered X-Forwarded-For and friends. SendDefaultPii = false skips exactly one thing, the Cookie header (ScopeExtensions.cs:140, SystemWebRequestEventProcessor.cs:62); there is no forwarded/IP/Via filtering anywhere in src/. So headers and query params resolve to a plain DenyList() whatever SendDefaultPii says, and cookies to Off when it is false. That is also what sentry-java's resolver actually does (explicitOrEmptyDenyList, and off() for cookies) as opposed to what the spec prescribes for a from-scratch SDK. Turning those terms on by default for legacy users stays available as a deliberate change in #5422.

    Side effect: the KeyValueCollectionBehavior.DenyList doc shipped in #5853 claims those terms "restore the header filtering that SendDefaultPii applied when disabled". There was no such filtering to restore, so #5885 rewords it to present them as the terms the spec names for filtering end-user-identifying keys.

    HTTP bodies resolve per direction — IncomingRequestBody, OutgoingRequestBody, IncomingResponseBody, OutgoingResponseBody — rather than exposing HttpBodyTypes, since that is what a call site needs and sentry-java found the legacy gate differs per direction. In .NET all four fall back to SendDefaultPii, which is faithful: the GraphQL handler gates both client-side bodies on it, and incoming request bodies are governed by MaxRequestBodySize, an integration option that keeps taking precedence.

    Per-site legacy gates get a sibling accessor with that fallback, rather than bending the shared bridge — sentry-java's isGraphqlDocumentWithLegacyBodyGate() pattern. None added yet, since none has a consumer until #5432.

    On the doc caveats (point 2 of the comment above): they are reworded rather than deleted. The resolver alone does not make the options live — nothing calls it until Phase 2 migrates the first consumer — so deleting the caveat now would have made the docs overstate what the SDK does, the mirror of the problem it was meant to fix. ConfigureDataCollection now states the SendDefaultPii replacement in the present tense, which is true of the resolver, and keeps a one-line caveat that the integrations are still being migrated. That line disappears for real as Phase 2 lands.

  5. jamescrosswell commented on Nov 8, 2026

    @jamescrosswell
    CollaboratorAuthor

    Correction to the decisions note above

    Two things in the decisions comment were wrong, both caught by @ric-oliv reviewing #5885.

    "SendDefaultPii = false only skips the Cookie header" holds for the server-side capture path only (ScopeExtensions.cs:140, SystemWebRequestEventProcessor.cs:62). SentryHttpFailedRequestHandler and SentryGraphQLHttpFailedRequestHandler are all-or-nothing: no request or response headers, neither cookie set, and Request.Url reduced to scheme + host + path. The global RequestHeaders / ResponseHeaders / UrlQueryParams fallbacks are still right — they are faithful to the majority of call sites, and making them follow SendDefaultPii would stop collecting all inbound request headers for every SendDefaultPii = false app — but the client-side handlers need the sibling accessors instead of the shared bridge.

    "None added yet, since none has a consumer until #5432" therefore understated it: #5429 needs the same three …WithLegacyPiiGate accessors, and is likely to land first. Noted on #5429 and #5432 field by field, including that Request.QueryString is set unconditionally today while Request.Url is not, so those two fields migrate differently.

    Two further bridge details settled in the PR, neither of which was in the issue text:

    #5420's bridge bullet now carries all of this.

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

Metadata

Metadata

Labels

FeatureNew feature or requestTask

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions