feat(sentry): replace Sentry user context with searchable identity tags - #1870
feat(sentry): replace Sentry user context with searchable identity tags#1870giladresisi wants to merge 1 commit into
Conversation
Drop Sentry.setUser entirely and carry the acting identity as plain tags instead: user.email, user.id, organization, organization.id (backend authenticated + frontend; public-API events keep org tags only, stripe customer tag unchanged). Frontend clears all tags on logout. Rationale: the user context (Contexts section) is display-only - not searchable - and everything it held is already in the tags, which are indexed and filterable. Dropping setUser also removes the id:/email: prefixes Sentry bakes into its synthesized user tag, so tag values are now the bare email/ids. A bare 'user' tag was attempted (user: <email>) but Sentry silently discards it - 'user' is a reserved tag key for the synthesized user tag (https://docs.sentry.io/platforms/javascript/enriching-events/tags/). The UI still groups user.email/user.id under a "user" heading, so nothing is lost. Verified with a real event: user.email, user.id, organization and organization.id all present with unprefixed values, no User card in Contexts, reserved 'user' tag confirmed dropped. Trade-offs accepted: issue "users affected" counts revert to IP-based estimates, replays lose user attribution, and user.id:<x> search syntax is replaced by the equivalent tag query. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
| Sentry.setTag('user.email', undefined); | ||
| Sentry.setTag('user.id', undefined); | ||
| Sentry.setTag('organization', undefined); | ||
| Sentry.setTag('organization.id', undefined); |
There was a problem hiding this comment.
Bug: User context is cleared on logout by setting tags to undefined with Sentry.setTag, which is not the standard Sentry API and may not work as intended.
Severity: MEDIUM
Suggested Fix
To correctly clear the user context upon logout, replace the calls to Sentry.setTag(..., undefined) with a single call to Sentry.setUser(null). This is the documented and standard API for resetting user information in Sentry.
Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location:
libraries/react-shared-libraries/src/sentry/initialize.sentry.client.ts#L17-L20
Potential issue: On logout, user identity tags are set to `undefined` using
`Sentry.setTag`. This is not the standard Sentry API for clearing user context. The
behavior is undefined; if the Sentry SDK converts `undefined` to the string "undefined",
then user identity tags like `user.email` and `user.id` would persist with this string
value after logout. This would be a regression and a privacy concern, as user context
would not be properly cleared.
Did we get this right? 👍 / 👎 to inform future reviews.
There was a problem hiding this comment.
Not a bug - verified empirically with the SDK: after setTag(key, undefined) the event's serialized tags no longer contain the key (envelopes are JSON-serialized and undefined values are dropped), so nothing persists after logout, and no "undefined" string appears. The suggested fix is incorrect for this code: setUser(null) does not clear tags - that's exactly the gap this same check flagged on #1800, which these setTag(..., undefined) calls fix.
What kind of change does this PR introduce?
Feature — follow-up to #1800 (telemetry identity enrichment).
Why was this change needed?
The Sentry user context set via
Sentry.setUser(#1800) has two drawbacks:usertag renders with a field prefix (id:3bd12314-.../email:...) which is noise when scanning or copying values.This PR drops
Sentry.setUserentirely and carries identity as plain tags instead:user.email,user.id,organization,organization.id— bare, unprefixed values. Backend authenticated requests and the frontend send all of them; public-API events keep org tags only (no user exists there); thestripe.customer_idtag is unchanged. The frontend clears all identity tags on logout.Note on the reserved
usertag: a bareuser: <email>tag was attempted, but Sentry silently discards a directly-setusertag — it's a reserved key for the synthesized one (https://docs.sentry.io/platforms/javascript/enriching-events/tags/). The Tags UI still groupsuser.email/user.idunder a "user" heading, so nothing is lost.Verified with a real event in the cloud project:
user.email,user.id,organization,organization.idall present with unprefixed values; no User card in Contexts; the reservedusertag confirmed dropped by the server.Trade-offs accepted: issue "users affected" counts revert to IP-based estimates, session replays lose user attribution, and
user.id:<x>search syntax is replaced by the equivalent tag query (user.idas a tag key).Other information:
Backend and frontend builds pass. Discussed and verified interactively before opening this PR.
Checklist:
🤖 Generated with Claude Code