Skip to content

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

Merged
jpnurmi merged 7 commits into
masterfrom
jpnurmi/feat/user-id
May 4, 2026
Merged

feat: enrich events by auto-populating user.id#1661
jpnurmi merged 7 commits into
masterfrom
jpnurmi/feat/user-id

Conversation

@jpnurmi

@jpnurmi jpnurmi commented Apr 21, 2026

Copy link
Copy Markdown
Collaborator

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

github-actions Bot commented Apr 21, 2026

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

Generated by 🚫 dangerJS against e46cd06

Comment thread src/sentry_scope.c Outdated
Comment thread src/sentry_session.c
Comment thread src/sentry_core.c Outdated
Comment thread src/sentry_session.c
@jpnurmi jpnurmi force-pushed the jpnurmi/feat/user-id branch 2 times, most recently from f2c34a3 to ac5b39a Compare April 27, 2026 10:23
jpnurmi and others added 6 commits May 4, 2026 10:09
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 ac5b39a to 47631fc Compare May 4, 2026 08:10
Comment thread src/sentry_database.c
@jpnurmi jpnurmi requested review from JoshuaMoelans and mujacica May 4, 2026 09:08

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

nice, LGTM!

@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 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 e46cd06. Configure here.

Comment thread src/sentry_core.c
@jpnurmi jpnurmi merged commit 4d3a7a9 into master May 4, 2026
131 of 134 checks passed
@jpnurmi jpnurmi deleted the jpnurmi/feat/user-id branch May 4, 2026 14:55
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

3 participants