Skip to content

feat(data-collection): create DataCollection option in client#6702

Merged
ericapisani merged 24 commits into
masterfrom
ep/db-spec-experiement-foundation-dict
Jul 8, 2026
Merged

feat(data-collection): create DataCollection option in client#6702
ericapisani merged 24 commits into
masterfrom
ep/db-spec-experiement-foundation-dict

Conversation

@ericapisani

@ericapisani ericapisani commented Jun 30, 2026

Copy link
Copy Markdown
Member

Support more granular PII controls via the data_collection option as seen in the spec.

These changes:

  • introduce the option
  • normalizes the user-provided options into a DataCollection dict
  • handles populating the data_collection option based on what the user provided, and whether or not send_default_pii (which will eventually be legacy) was set.

They don't currently hook up to anything in order to keep the size of this pull request somewhat sane.

Some high-level design decisions to call out:

  1. Introducing 2 types for the different config options - one that's more flexible for user input, the other more strict after we've received the input.

This was done so that, once we've received the config from the user and have set defaults for values that weren't provided, we can avoid needing to constantly check if the value is None within the SDK.

  1. Including a provided_by_user property within the DataCollection type

This is mainly to deal with spotlight-related logic within the client, which you can see here.

Fixes PY-2570
Fixes #6700

@github-actions

github-actions Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Codecov Results 📊

90435 passed | ⏭️ 6302 skipped | Total: 96737 | Pass Rate: 93.49% | Execution Time: 315m 59s

📊 Comparison with Base Branch

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

All tests are passing successfully.

✅ Patch coverage is 98.18%. Project has 2439 uncovered lines.
✅ Project coverage is 89.79%. Comparing base (base) to head (head).

Files with missing lines (1)
File Patch % Lines
sentry_sdk/data_collection.py 98.04% ⚠️ 1 Missing and 2 partials
Coverage diff
@@            Coverage Diff             @@
##          main       #PR       +/-##
==========================================
+ Coverage    89.74%    89.79%    +0.05%
==========================================
  Files          192       193        +1
  Lines        23823     23878       +55
  Branches      8226      8244       +18
==========================================
+ Hits         21378     21439       +61
- Misses        2445      2439        -6
- Partials      1349      1351        +2

Generated by Codecov Action

@ericapisani ericapisani changed the base branch from ep/db-spec-experiment-foundation to master July 2, 2026 19:43
@ericapisani ericapisani changed the title ref(data-collection): Rework DataCollection as a TypedDict, drop accessors feat(data-collection): create DataCollection option in client Jul 2, 2026
…ssors

Replace the class-based DataCollection/KeyValueCollectionBehavior/
GenAICollection/HttpHeadersCollection API with plain TypedDicts
(DataCollection, DataCollectionUserOptions, and per-category
*CollectionBehaviour/*UserOptions types) defined in _types.py.

Collection mode strings move from camelCase (denyList/allowList) to
snake_case (deny_list/allow_list) to match Python convention, since
this is a Python-only deviation from the spec that is never
serialized to Sentry.

Drop the should_collect_user_info/should_collect_gen_ai_inputs/
should_collect_gen_ai_outputs accessor methods and their module-level
shortcuts in favor of reading data_collection fields directly, and
drop the public sentry_sdk.DataCollection/GenAICollection/
HttpHeadersCollection/KeyValueCollectionBehavior exports.

Revert the Unreleased CHANGELOG entry and README example for the
prior class-based API.
@ericapisani ericapisani force-pushed the ep/db-spec-experiement-foundation-dict branch from 1d30c98 to 8b9dedb Compare July 2, 2026 19:47
Comment thread tests/test_data_collection.py
Comment thread tests/test_data_collection.py
Comment thread sentry_sdk/client.py
Comment thread sentry_sdk/data_collection.py
Comment thread sentry_sdk/data_collection.py Outdated
@ericapisani

Copy link
Copy Markdown
Member Author

bugbot run

Comment thread sentry_sdk/client.py Outdated
Comment thread sentry_sdk/client.py
@ericapisani ericapisani marked this pull request as ready for review July 3, 2026 13:04
@ericapisani ericapisani requested a review from a team as a code owner July 3, 2026 13:04
@linear-code

linear-code Bot commented Jul 3, 2026

Copy link
Copy Markdown

PY-2570

Comment thread sentry_sdk/data_collection.py Outdated

@alexander-alderman-webb alexander-alderman-webb 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.

Just did a quick pass, not a proper review.
Can we add underscores to everything we don't want users to access? 🙏

Comment thread sentry_sdk/data_collection.py Outdated
Comment thread sentry_sdk/data_collection.py Outdated
Comment thread sentry_sdk/data_collection.py Outdated
Comment thread sentry_sdk/data_collection.py Outdated
Comment thread sentry_sdk/client.py Outdated
Comment thread sentry_sdk/client.py Outdated

@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 3 potential issues.

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 15c21c0. Configure here.

Comment thread sentry_sdk/client.py
include_local_variables=self.options["include_local_variables"]
is not False,
include_source_context=self.options["include_source_context"]
is not False,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Spotlight frame flags disagree

Medium Severity

In DSN-less Spotlight mode, re-derived data_collection uses include_local_variables is not False (and the same for include_source_context), while _resolve_data_collection treats those options with bool(value) when they are not None. Falsy non-boolean values such as 0 resolve to disabled frame settings initially but become enabled after the Spotlight override.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 15c21c0. Configure here.

Comment thread sentry_sdk/client.py Outdated
@property
def data_collection(self) -> "DataCollection":
return _DISABLED_DATA_COLLECTION_CONFIG

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unpickled client missing data_collection

Low Severity

_Client.__setstate__ restores options from pickled state and calls _init_impl without ensuring a resolved data_collection entry exists. Clients pickled before this option was added have no data_collection key, so DSN-less Spotlight setup or the new data_collection property can raise KeyError.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 15c21c0. Configure here.

Comment thread sentry_sdk/data_collection.py
…s - we don't currently support gating on that today within the Python SDK
Comment thread sentry_sdk/data_collection.py
Comment thread sentry_sdk/data_collection.py
@ericapisani ericapisani marked this pull request as draft July 6, 2026 13:38
@ericapisani

Copy link
Copy Markdown
Member Author

Moving back to draft while I investigate the bot comments

Comment thread sentry_sdk/scope.py Outdated

@sentrivana sentrivana 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.

LGTM. Left a few comments.

Comment thread sentry_sdk/_types.py Outdated
Comment thread sentry_sdk/_types.py
class HttpHeadersCollectionBehaviour(TypedDict):
request: "KeyValueCollectionBehaviour"

class DataCollectionUserOptions(TypedDict, total=False):

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.

For my understanding, we have these type pairs (UserOptions and Behaviour) so that users don't need to specify all options (total=False on the UserOptions types), but also so that the materialized DataCollection that we'll use internally won't nag us about an option potentially being None, because it has to be fully filled out with default values in case any are missing, right?

I see why we have it like this but I'm afraid the two might drift eventually because we forget to update one of them.

It's not like I have better ideas 😀 The complexity we introduce with the config needs to be dealt with someplace, and I guess this is an ok place.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

For my understanding, we have these type pairs (UserOptions and Behaviour) so that users don't need to specify all options (total=False on the UserOptions types), but also so that the materialized DataCollection that we'll use internally won't nag us about an option potentially being None, because it has to be fully filled out with default values in case any are missing, right?

Yup, you've got it! I wanted to spare us from all the extra code we'd have to write to satisfy the typechecker when performing the checks within the integrations 😅

I agree with you about the risk of drift. I thought it'd be worth it in this case because after the data collection spec is implemented and settled, the amount of updates we'd need to do here would likely be minimal.

If we think of anything better throughout the implementation of the spec though, happy to come back and change the approach! 😄

Comment thread sentry_sdk/data_collection.py Outdated
Comment thread sentry_sdk/data_collection.py Outdated
Comment thread sentry_sdk/data_collection.py Outdated
Comment thread sentry_sdk/data_collection.py Outdated
Comment thread sentry_sdk/data_collection.py Outdated
Comment thread sentry_sdk/consts.py
Comment thread CHANGELOG.md
@ericapisani ericapisani marked this pull request as ready for review July 7, 2026 18:37
Comment thread sentry_sdk/data_collection.py
@ericapisani ericapisani merged commit 9f3c89a into master Jul 8, 2026
271 of 273 checks passed
@ericapisani ericapisani deleted the ep/db-spec-experiement-foundation-dict branch July 8, 2026 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create DataCollection option in client

3 participants