Repository navigation
feat: add experimental DataCollection options, successor to SendDefaultPii - #5853
Conversation
…ltPii Adds the option shape from the DataCollection spec as a no-op: nothing reads it yet. The resolver and SendDefaultPii bridge follow in #5426. Co-Authored-By: Claude Opus 5 <[email protected]>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #5853 +/- ##
==========================================
+ Coverage 76.55% 76.65% +0.10%
==========================================
Files 528 531 +3
Lines 19624 19713 +89
Branches 3873 3895 +22
==========================================
+ Hits 15023 15111 +88
- Misses 3715 3716 +1
Partials 886 886 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Mirrors DataCollectionOptions in BindableSentryOptions so the option can be set from appsettings.json, following the nested-bindable pattern used by the platform options. KeyValueCollectionBehavior has no public constructor, so it binds through a Mode/Terms surrogate. Co-Authored-By: Claude Opus 5 <[email protected]>
…nable() Assigning the option is now the opt-in signal, matching sentry-go, sentry-php, sentry-python and sentry-javascript. Removes Enable() and the internal bookkeeping it needed to distinguish an unset option from a default one. Co-Authored-By: Claude Opus 5 <[email protected]>
|
@ric-oliv this looks like a big PR - it's mostly mechanical though... simply adds an options type - a bindable options type around that and the bulk of the PR is in the approvals snapshots that change. |
An explicit null for a params array is legal, so DenyList(null) and AllowList(null) produced an instance whose Terms was null, which would throw in any consumer that iterates it. Coalesce in the constructor so both factories are covered. Co-Authored-By: Claude Opus 5 <[email protected]>
The bool shorthand code has for cookies, headers and query params has no configuration equivalent, so a scalar is dropped by the binder. Document the supported shape on the public type and lock the behavior with a test. Co-Authored-By: Claude Opus 5 <[email protected]>
Swaps the IncomingResponse/OutgoingResponse doc comments, which described the wrong direction. Gives KeyValueCollectionBehavior a public constructor and settable properties so the reflection binder can construct it: on netstandard2.0 the options are bound directly rather than through BindableSentryOptions, and any key-value category threw there. Binds HttpBodies from an array so the spec's empty-array opt-out works instead of silently collecting every body. Adds coverage for the four ApplyTo lines no test reached. Co-Authored-By: Claude Opus 5 <[email protected]>
…in config A JSON empty array emits a valueless key with no children, which the binder surfaces as null, so "[]" cannot be told apart from the option being absent and did not disable body collection. The previous test asserted against a hand-built list rather than the binder, so it did not catch this. Co-Authored-By: Claude Opus 5 <[email protected]>
The source-generated binder keeps null array elements, so a null entry in HttpBodies reached Split and threw. Enum.TryParse already handles comma lists, spacing and casing for a flags enum and rejects null, so the manual splitting is gone. Sentry.Tests binds with the reflection binder, which drops nulls, so the crash only shows up through SentryLoggingOptionsSetup, which now covers DataCollection keys. Also filters null and empty terms, which would otherwise match every key, marks HttpBodyTypes and KeyValueCollectionMode experimental like the rest of the new surface, and drops tests that only fail when a neighbour already does. Co-Authored-By: Claude Opus 5 <[email protected]>
On .NET Framework the logging setup binds onto the options directly rather than through BindableSentryOptions, so indexed HttpBodies keys never reach ParseHttpBodies and the category binds as None instead of the requested flags. Co-Authored-By: Claude Opus 5 <[email protected]>
The logging setup bound configuration straight onto the options on netstandard2.0, so an indexed key under HttpBodies made the reflection binder try to construct Nullable<HttpBodyTypes> and throw. It now binds through BindableSentryLoggingOptions on every target, as net6.0 and later already did, which also removes the divergence where .NET Framework read HttpBodies as a different value to .NET 8 and later. The bindable parity test for SentryLoggingOptions has no skipped properties, so the surrogate covers everything the direct bind did. Co-Authored-By: Claude Opus 5 <[email protected]>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 598d0c7. Configure here.
…removed The script that dropped the low-value tests searched from the first [Fact] in the file, so each deletion also took every test above it and left two empty classes. Nothing covered the Terms filtering, the fresh Off instance or the bool conversion; all three now fail under mutation again. Drops BindableDataCollectionReflectionTests as redundant: Sentry.Tests does not run the binding generator, so DataCollectionConfigurationTests already exercises the surrogate with the reflection binder. Co-Authored-By: Claude Opus 5 <[email protected]>
Mcp, Queues, FilePaths, StackFrameVariables and FrameContextLines had no consumer anywhere in src/: there is no MCP instrumentation, nothing captures queued job arguments, there is no file-system instrumentation, and nothing populates SentryStackFrame.Vars, PreContext, PostContext or ContextLine. The spec is still a candidate and has renamed or retyped options since June, so a public property for something we do not instrument locks in today's shape, while adding one later never breaks anyone. DatabaseQueryData and GenAI stay - see #5433 and #5434. Co-Authored-By: Claude Opus 5 <[email protected]>
`SentryOptions.DataCollection` was a nullable property whose presence was the opt-in signal, which made the natural way to write every category throw. Eleven properties were nullable, so `options.DataCollection.UserInfo = false` and `dataCollection.HttpHeaders.Request.Mode = ...` both NRE'd, and assigning a new instance inside `UseSentry` silently discarded anything bound from appsettings.json, since configuration binding runs first. Replace it with `ConfigureDataCollection(Action<DataCollectionOptions>)`. Calling it is the opt-in, so nothing is inferred from which fields were set; the options it hands over start at the spec defaults and are non-null all the way down, so every category can be set or mutated in place. Repeated calls build on the same instance, and so does configuration, which still binds through the surrogate. Constructors become internal: the only way to reach the options is the callback, so a `new DataCollectionOptions()` that silently did nothing is no longer expressible. This reduces the public surface while the API is experimental. Co-Authored-By: Claude Opus 5 <[email protected]>
|
|
Nice, the callback reads well. I'd leave the opt-in as is. |
Terms only mean something next to their Mode, so in-place edits let code and configuration combine into a behavior neither side wrote: config supplying Terms while code sets Mode = AllowList yields AllowList[those terms], and code appending a deny term to a config-set allow list widens it instead. Dropping the public constructor and the Mode/Terms setters leaves Off(), DenyList() and AllowList() as the only ways to build one, matching the spec's Java example and its requirement that the type make mixing deny and allow terms impossible. Each category is now replaced whole, from either side. Config keeps treating Terms without Mode as a deny list, which is the spec default. Co-Authored-By: Claude Opus 5 <[email protected]>
SentryLoggingOptionsSetup conflicted: main renamed the provider type parameter to SentryStructuredLoggerProvider in both halves of the #if NET6_0_OR_GREATER split (#5872), while this branch removed the #else half entirely. Kept the removal and took the rename in the surviving half. Co-Authored-By: Claude Opus 5 <[email protected]>
…s review nits The XML docs described the destination in the present tense: that calling ConfigureDataCollection replaces SendDefaultPii, which is then ignored. Nothing reads DataCollection yet, so SendDefaultPii still governs collection entirely and restricting a category has no effect. Both facts are now stated, and the replacement is in the future tense, conditional on the integrations migrating. Also from review: cover a key-value category in the config-merge test, so the suite notices if ToBehavior stops returning null for an untouched surrogate and starts resetting categories config never mentioned; drop the per-category independence test, which only meant something while behaviors were mutable; correct a stale StackFrameVariables mention; remove a stray blank line. Co-Authored-By: Claude Opus 5 <[email protected]>
#5853 was squash-merged, so the branch commits this stack carried were no longer ancestors of main. Resolve every DataCollection file to main's version; this branch contributes only SensitiveDataFilter and its tests. Co-Authored-By: Claude Opus 5 <[email protected]>
KeyValueCollectionBehavior sanitizes its own Terms as of #5853, so the four behavior-level null/empty-term tests duplicated DataCollectionOptionsTests. additionalDenyTerms is caller-supplied and unsanitized, so test the guard there. Co-Authored-By: Claude Opus 5 <[email protected]>
#5440) * ref: Add internal sensitive-data denylist and key-value filter utility First step of the DataCollection migration (#5420, #5421). Internal only, nothing wired up yet. Mirrors filterKeyValueData/filtering-snippets from the JS reference implementation. Co-Authored-By: Claude Fable 5 <[email protected]> * ref: Align sensitive-data filter with the spec and the Java SDK Ignore empty and null terms when matching: an empty term would otherwise filter every value in deny-list mode and allow every value through in allow-list mode, which becomes reachable once terms are bound from configuration. Trim the denylist to the spec's canonical 17 terms. Treating cookie and set-cookie as substring terms over-filtered every other category; the exact header-name rule belongs at the header call site (#5422). Decode keys before matching so an encoded key such as %74oken is recognised, while callers still store the raw key and value. Return an ordered list rather than a dictionary, so repeated headers such as Set-Cookie are preserved instead of silently collapsed. Co-Authored-By: Claude Opus 5 <[email protected]> * feat: add experimental DataCollection options, successor to SendDefaultPii Adds the option shape from the DataCollection spec as a no-op: nothing reads it yet. The resolver and SendDefaultPii bridge follow in #5426. Co-Authored-By: Claude Opus 5 <[email protected]> * ref: Remove unreachable branches from the sensitive-data filter Uri.UnescapeDataString never throws on malformed input, it returns the input unchanged, so the UriFormatException handler could not run. Off mode now returns [Filtered] from FilterValue instead of being asserted away, which drops the unreachable default switch arm and makes the mode's result explicit. Co-Authored-By: Claude Opus 5 <[email protected]> * feat: bind DataCollection options from configuration Mirrors DataCollectionOptions in BindableSentryOptions so the option can be set from appsettings.json, following the nested-bindable pattern used by the platform options. KeyValueCollectionBehavior has no public constructor, so it binds through a Mode/Terms surrogate. Co-Authored-By: Claude Opus 5 <[email protected]> * ref: make SentryOptions.DataCollection nullable instead of exposing Enable() Assigning the option is now the opt-in signal, matching sentry-go, sentry-php, sentry-python and sentry-javascript. Removes Enable() and the internal bookkeeping it needed to distinguish an unset option from a default one. Co-Authored-By: Claude Opus 5 <[email protected]> * ref: Use the public KeyValueCollectionBehavior in the sensitive-data filter The internal KeyValueFilterBehavior/KeyValueFilterMode pair was written when this phase was expected to land before the public option shape. That shape now exists with identical modes and semantics, so the internal pair was duplication and is removed. MatchesAny tolerates a null term list, because DenyList(null) leaves Terms null and the SDK must not throw while capturing an event. It also iterates by index, since IReadOnlyList allocates an enumerator where an array does not and this runs per key per event. Co-Authored-By: Claude Opus 5 <[email protected]> * fix: KeyValueCollectionBehavior.Terms is never null An explicit null for a params array is legal, so DenyList(null) and AllowList(null) produced an instance whose Terms was null, which would throw in any consumer that iterates it. Coalesce in the constructor so both factories are covered. Co-Authored-By: Claude Opus 5 <[email protected]> * ref: Let the null-term guard carry the nullable deny-terms argument additionalDenyTerms is nullable, so passing it straight to MatchesAny replaces a second null check at the call site and keeps the guard load-bearing now that KeyValueCollectionBehavior.Terms is never null. Co-Authored-By: Claude Opus 5 <[email protected]> * docs: note that key-value categories bind from Mode/Terms, not a scalar The bool shorthand code has for cookies, headers and query params has no configuration equivalent, so a scalar is dropped by the binder. Document the supported shape on the public type and lock the behavior with a test. Co-Authored-By: Claude Opus 5 <[email protected]> * fix: make DataCollection bind correctly on all configuration paths Swaps the IncomingResponse/OutgoingResponse doc comments, which described the wrong direction. Gives KeyValueCollectionBehavior a public constructor and settable properties so the reflection binder can construct it: on netstandard2.0 the options are bound directly rather than through BindableSentryOptions, and any key-value category threw there. Binds HttpBodies from an array so the spec's empty-array opt-out works instead of silently collecting every body. Adds coverage for the four ApplyTo lines no test reached. Co-Authored-By: Claude Opus 5 <[email protected]> * fix: document that the HttpBodies empty-array opt-out needs ["None"] in config A JSON empty array emits a valueless key with no children, which the binder surfaces as null, so "[]" cannot be told apart from the option being absent and did not disable body collection. The previous test asserted against a hand-built list rather than the binder, so it did not catch this. Co-Authored-By: Claude Opus 5 <[email protected]> * test: cover the empty-term guard where it is now load-bearing KeyValueCollectionBehavior sanitizes its own Terms as of #5853, so the four behavior-level null/empty-term tests duplicated DataCollectionOptionsTests. additionalDenyTerms is caller-supplied and unsanitized, so test the guard there. Co-Authored-By: Claude Opus 5 <[email protected]> * test: drop two empty-term tests that pin neither guard Verified by mutation: with the empty-term guard removed from MatchesAny both stayed green, while the additionalDenyTerms theories failed. The behavior type strips the term before it reaches the guard. Also document that Off requires the caller to drop the key, since FilterValue returns [Filtered] there only to fail closed. Co-Authored-By: Claude Opus 5 <[email protected]> * fix: do not let a malformed escape throw out of DecodeKeyForMatching Uri.UnescapeDataString returns the input unchanged for a malformed escape on modern .NET but throws UriFormatException on .NET Framework. sentry-java guards the same call in decodeQueryParamName. #5424 feeds untrusted query keys through here, and the SDK must not throw while enriching an event. Co-Authored-By: Claude Opus 5 <[email protected]> --------- Co-authored-by: Claude Fable 5 <[email protected]>

Closes #5425
Closes #5427
First code step of the DataCollection migration (#5420, spec 0.15.0). Adds the public option shape and its configuration binding as a no-op — the options can be set, in code or from
appsettings.json, but nothing reads them yet. The resolver andSendDefaultPiibridge that give them behavior are #5426.DataCollectionOptions— every spec category, all nullable so "unset" stays distinguishable from "explicitly set" (the bridge in DataCollection phase 1: resolver and SendDefaultPii bridge #5426 depends on that). Sub-groups (HttpHeaders,GraphQL,GenAI,Mcp) are non-null instances so they can be configured without a null check.KeyValueCollectionBehavior+KeyValueCollectionMode—Off/DenyList(...)/AllowList(...), mirroring what sentry-java shipped in 8.58.0 rather than the JSboolean | {allow} | {deny}union.[Flags] HttpBodyTypes— the idiomatic .NET form of the spec's body-type array (Set<HttpBodyType>in Java).SentryOptions.DataCollectionis nullable and unset by default. Assigning it is the opt-in signal, so DataCollection phase 1: resolver and SendDefaultPii bridge #5426's resolver keys offoptions.DataCollection is not nullrather than any bookkeeping of our own, andSendDefaultPiigoverns until then.Defaults live in the resolver, not here, so the properties carry no initializers; the documented default for each category is in its XML docs.
Decisions worth a look
[Experimental(SENTRY0001)]. The spec is stillcandidate, and this PR ships an option that does nothing, so consumers have to acknowledge SENTRY0001 to touch it. I'd suggest dropping the attribute once Phase 2 is wired. If you'd rather it not appear in release notes at all in the meantime, say so and I'll addskip-changelog— I left thefeat:title so early adopters can see the shape and push back on it.Enable()method. An earlier revision of this branch had anEnable()method modelled on sentry-java'sforceDataCollection(). sentry-java turns out to be the only SDK that exposes such a method: sentry-go (*sentry.DataCollection), sentry-php (nulldefault), sentry-python (Optional, with an internalprovided_by_userflag) and sentry-javascript all make the container itself absent by default and treat touching it as the opt-in. sentry-cocoa needs nothing becausedataCollectionandsendDefaultPiiare mutually exclusive by compilation (#if SDK_V10/#if !SDK_V10), and sentry-ruby needs nothing because each unset field backfills fromsend_default_piiper-field. Following the four-SDK majority removes an invented API and the internal state it required. The cost is that this is the only sub-option onSentryOptionsthat is nullable — butNative/Android/Experimentalhave no legacy flag to arbitrate against, so their non-nullness isn't really a precedent.bool→KeyValueCollectionBehavior(true=DenyList(),false=Off). This is how the spec'sbool | KeyValueCollectionBehaviortype forStackFrameVariables(0.9.0) is satisfied without a union type, and it makesCookies = falsework the way JS users would expect.GenAIOptionsandMcpOptionsare separate types despite being structurally identical. The spec gives them different semantics and they may diverge; merging them now would be the harder thing to undo.Mcp,FilePaths,Queues,StackFrameVariables,FrameContextLinesare present but unactionable in managed code — we have no MCP or file-I/O instrumentation, and Hangfire/Quartz/Quartz3 don't capture arbitrary job arguments. They're here for spec completeness and native forwarding (DataCollection phase 2: propagate to native (Android/Cocoa) #5436). Adding categories late is what forced the JS SDK to re-gate integrations.🤖 Generated with Claude Code