Skip to content

feat: enrich events by auto-populating user.id#1661

Open
jpnurmi wants to merge 6 commits intomasterfrom
jpnurmi/feat/user-id
Open

feat: enrich events by auto-populating user.id#1661
jpnurmi wants to merge 6 commits intomasterfrom
jpnurmi/feat/user-id

Conversation

@jpnurmi
Copy link
Copy Markdown
Collaborator

@jpnurmi jpnurmi commented Apr 21, 2026

Generate a stable per-installation UUID and use it as the default user.id when the SDK user has no explicit ID set. The UUID is persisted in <db>/installation_id alongside the DSN public key so that changing DSNs rotates the ID, and is stamped onto events at scope-apply time without mutating the user-provided scope.

Sentry uses user.id to compute the number of users impacted by an issue (distinct from event counts); this gives developers that metric out of the box. DSN scoping keeps it privacy-conscious — the ID is not a stable identity across installations. Matches sentry-android, sentry-cocoa, and sentry-dotnet.

Note: sentry_value_new_user[_n] now preserves an explicit empty-string id instead of dropping it; only NULL skips the field. This lets the new auto-ID enrichment distinguish "no ID set" vs. "ID explicitly empty".

Close: #1324

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 21, 2026

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against f2c34a3

Comment thread src/sentry_scope.c Outdated
Comment thread src/sentry_session.c
Comment thread src/sentry_core.c Outdated
Copy link
Copy Markdown

@cursor cursor Bot left a comment

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 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 2af7ee3. Configure here.

Comment thread src/sentry_session.c
jpnurmi and others added 6 commits April 25, 2026 09:26
Generate a stable per-installation UUID and use it as the default
`user.id` when the SDK user has no explicit id set. The UUID is
persisted in `<db>/installation_id` alongside the DSN public key so
that changing DSNs rotates the id, and is stamped onto events at
scope-apply time without mutating the user-provided scope.

Close: #1324

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Initialize scope->user to an empty object so the null state is reserved
for explicit sentry_remove_user(). At event apply, skip user enrichment
entirely when scope->user is null (removed). Guard the two sites that
previously fell through on is_null(scope->user) against leaking an empty
object into events / crash-recovery payloads.

Use installation_id as the session distinct_id fallback when user has no
explicit id. Drops the previous email/username fallback chain to align
with sentry-java/sentry-cocoa and the session spec requirement that did
be stable for the session lifetime.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Centralize the "user.id or installation_id" resolution so both the event
and session call sites share the same helper.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The helper mutated its user argument, which leaked out through
sentry_set_user (caller's value) and sentry__session_sync_user
(scope->user). Revert the helper and inline both sites again.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@jpnurmi jpnurmi force-pushed the jpnurmi/feat/user-id branch from 52ce9c5 to f2c34a3 Compare April 25, 2026 07:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Set a persisted uuid as user.id so Sentry can identify number of impacted users

1 participant