Skip to content

feat: DataCollection.UserInfo now gates the environment username and inferred IP address - #5932

Open
jamescrosswell wants to merge 2 commits into
mainfrom
ai/dc-5428-user-info-5e7cfd
Open

jamescrosswell wants to merge 2 commits into
mainfrom
ai/dc-5428-user-info-5e7cfd

Conversation

@jamescrosswell

@jamescrosswell jamescrosswell commented Nov 16, 2026 •

Copy link
Copy Markdown
Collaborator

The core SDK's automatic user info is now governed by the UserInfo data collection setting instead of SendDefaultPii. Enricher reads DataCollectionResolver.UserInfo before reporting the environment username (IsEnvironmentUser) and the {{auto}} IP address placeholder.

Part of #5420 (Phase 2).

Closes #5428

Behaviour

  • DataCollection not configured: unchanged. UserInfo bridges to SendDefaultPii.
  • ConfigureDataCollection(...) called: UserInfo (default true) decides, and SendDefaultPii is ignored, as the spec requires. An app that calls ConfigureDataCollection with SendDefaultPii = false and leaves UserInfo at its default now gets the environment username and {{auto}} IP. This affects only apps that opted into the experimental option shipped in 6.13.0 / 7.0.0.
  • User data set by the application is never gated. ??= and HasUser() only fill gaps, and a test pins that with UserInfo both on and off.

Notes for review

🤖 Generated with Claude Code

The environment username and the `{{auto}}` IP address now read
`DataCollectionResolver.UserInfo` instead of `SendDefaultPii`. When
`DataCollection` is not configured, `UserInfo` bridges to
`SendDefaultPii`, so behaviour is unchanged.

Refs #5428

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

codecov Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.70%. Comparing base (2e62117) to head (991f249).
⚠️ Report is 11 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5932      +/-   ##
==========================================
+ Coverage   77.44%   77.70%   +0.25%     
==========================================
  Files         546      535      -11     
  Lines       20053    19731     -322     
  Branches     3962     3934      -28     
==========================================
- Hits        15531    15332     -199     
+ Misses       3658     3544     -114     
+ Partials      864      855       -9     

☔ 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.

@ric-oliv ric-oliv left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

One small thing about Closes #5428. That issue is the only one tracking the server-name sites in MainSentryEventProcessor and SentryLog, so nothing would track them once it closes. Later, #5437 would deprecate SendDefaultPii, but it's still the only switch for server_name. Could we move those two sites to a follow-up issue?

Comment thread src/Sentry/Internal/Enricher.cs Resolved
With UserInfo disabled the enricher skips the whole block, so the old
test never exercised the HasUser() check. Running it with UserInfo both
on and off, and no username set, catches a dropped HasUser() check or a
switch to `Username ??=`.

Also note on DataCollectionOptions.UserInfo that the installation ID
still fills SentryUser.Id, per getsentry/sentry-docs#20856.

Refs #5428

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

github-actions Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Mutation testing breaks the lines a PR changes on purpose, one mutation at a time, and checks that a test fails each time. A changed line no test runs fails the check, and a mutant that survives the tests only warns. Full report

Sentry: tests caught 1 of 1 mutants on the changed lines

@jamescrosswell

Copy link
Copy Markdown
Collaborator Author

One small thing about Closes #5428. That issue is the only one tracking the server-name sites in MainSentryEventProcessor and SentryLog, so nothing would track them once it closes. Later, #5437 would deprecate SendDefaultPii, but it's still the only switch for server_name. Could we move those two sites to a follow-up issue?

So this relates to ServerName (Environment.MachineName) in MainSentryEventProcessor and the server.address log attribute in SentryLog. Both are still gated on SendDefaultPii. The spec's userInfo covers only user.id, user.email, user.username and user.ip_address, and never mentions server name.

SDK Default Gated on PII / userInfo? Off switch
Java hostname No attachServerName (default true), also used for logs and metrics
JavaScript (Node) SENTRY_NAME env var, else os.hostname() No includeServerName: false; documented as being for CLI and Electron apps where the hostname may be PII
Python socket.gethostname() No override server_name
Go os.Hostname() No override ServerName
Ruby Socket.gethostname, or DYNO on Heroku No override server_name
PHP gethostname() No override server_name

.NET is currently the only SDK that withholds the hostname unless SendDefaultPii is on.

Most SDKs just send it (the only option to turn it off is to overwrite it).

Java and Node have attachServerName and includeServerName options. It feels like that gate would sit well in the new Data Collection options, so I'll check with the other SDK teams what we actually want to do here, rather than just make something up.

@jamescrosswell

Copy link
Copy Markdown
Collaborator Author

@ric-oliv Good catch on Closes #5428. I've moved the server-name sites in MainSentryEventProcessor and SentryLog to #5957, and the description links it, so closing #5428 won't leave them untracked. #5957 proposes a top-level AttachServerName like Java's, defaulting to true, and to false on .NET for Android and iOS.

🤖 Addressed by Claude Code

ric-oliv added a commit to getsentry/sentry-docs that referenced this pull request Nov 18, 2026
## DESCRIBE YOUR PR

The data collection spec doesn't say whether `userInfo` covers the
installation ID that some SDKs generate and send as `user.id`, so SDKs
have read it both ways. Java keeps the ID independent of `userInfo` in
getsentry/sentry-java#5937, and Cocoa's v10 builds gate it in
getsentry/sentry-cocoa#8415. .NET has to pick one in
getsentry/sentry-dotnet#5932.

This PR adds an "Installation Identifier" section that writes down what
Java does:

- `dataCollection` options don't gate the installation identifier. It
identifies an installation, not a person.
- SDKs should generate it at random. They may use an ID the platform
provides and scopes to the app, like the console IDs
getsentry/sentry-native#2150 allows. They must not use values that
identify the device outside the app, like a MAC address or a host name.

It also points the `userInfo` row, the "Disable User Identity" example
and the technical context examples at the new section. The section adds
requirements, so the spec moves to 0.18.0.

Why Java's reading:

- The spec suggests `userInfo: false` to roughly match `sendDefaultPii:
false`, and `sendDefaultPii: false` always sent the installation ID.
- Gating only `user.id` doesn't keep the ID on the device, because
sessions send the same value as `did`. It would drop the "users
affected" counts and protect very little.
- Every SDK that has shipped already sends it. Only Cocoa's unreleased
v10 builds gate it.

I also considered gating it on `userInfo`, the way Cocoa v10 does. That
would need a rule for the session `did` too, and it would change
behavior in every shipped SDK.

For the SDKs, Java already follows this, Cocoa would drop the `SDK_V10`
gate before v10 ships, and .NET will follow up on its side.

## IS YOUR CHANGE URGENT?

- [ ] Urgent deadline (GA date, etc.): YYYY-MM-DD
- [ ] Other deadline: YYYY-MM-DD
- [x] No deadline: Not urgent, can wait up to 1 week+

@ric-oliv ric-oliv left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looking good! One optional thing: this is the first PR where a category actually changes what gets collected, so two remarks go stale once it merges. SentryOptions.ConfigureDataCollection says "setting a category here has no effect yet", and the DataCollectionOptions class remarks say "setting a category does not yet change what they collect". Both contradict the UserInfo docs now. #5931 doesn't touch them either, so whichever lands first could reword them. Maybe something like this, which won't need updating as each integration moves:

SentryOptions.ConfigureDataCollection:

/// The integrations are still being migrated onto these options. Those that haven't moved yet still follow
/// <see cref="SendDefaultPii"/> and ignore the categories set here.

DataCollectionOptions:

/// The integrations are still being migrated onto these options, and those that haven't moved yet ignore these
/// categories; see <see cref="SentryOptions.ConfigureDataCollection"/>.

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 core enricher (UserInfo)

2 participants