Skip to content

fix(sentry): set user email and username on Sentry user context#418

Draft
sentry-junior[bot] wants to merge 1 commit into
mainfrom
fix/sentry-user-email-attribution
Draft

fix(sentry): set user email and username on Sentry user context#418
sentry-junior[bot] wants to merge 1 commit into
mainfrom
fix/sentry-user-email-attribution

Conversation

@sentry-junior
Copy link
Copy Markdown
Contributor

@sentry-junior sentry-junior Bot commented May 26, 2026

Problem

The Sentry AI Conversations view showed Slack's infrastructure IPs instead of human-readable user identifiers. Investigation confirmed two bugs:

Bug 1 — username was silently dropped

setSentryTagsFromContext only calls Sentry.setUser() when context.slackUserId is present. The post-lookup setTags({ slackUserName: resolvedUserName }) call in reply-executor.ts passed slackUserName without slackUserId, so the guard was never satisfied and username was never written to the Sentry user object.

Bug 2 — email was never plumbed to Sentry

lookupSlackUser fetches profile.email from the Slack API, and reply-executor already passes fallbackIdentity?.email into generateAssistantReply for prompt context — but the field was missing from LogContext and never reached setUser().

Result: Sentry events had user.id = <SlackId> but user.username = null and user.email = null. The Conversations view fell back to user.ip, which captured Slack's egress IPs rather than the human user.

Changes

  • logging.ts — Add slackUserEmail?: string to LogContext. Thread email into both Sentry.setUser() (global scope) and scope.setUser() (per-exception scope).
  • reply-executor.ts — Consolidate the post-lookup setTags call to always include slackUserId alongside slackUserName and slackUserEmail, so the if (context.slackUserId) guard fires and all three fields land on the Sentry user object in one shot.

Verified

  • TypeScript: clean (tsc --noEmit)
  • Sentry logging unit tests: pass
  • Sentry broker unit tests: pass

Fixes attribution in the Sentry AI Conversations view — conversations will now show user.email (from Slack profile) and user.username (Slack display name) instead of infrastructure IPs.


View Session in Sentry

Action taken on behalf of Sergiy Dybskiy.

setSentryTagsFromContext and setSentryScopeContext only set user.id on
the Sentry user object. As a result, the Sentry AI Conversations view
falls back to showing user.ip (Slack's egress IPs) because neither
user.email nor user.username is present.

Two bugs:
- The slackUserEmail field was missing from LogContext and never plumbed
  into setUser(), even though lookupSlackUser fetches it from Slack's API.
- The post-lookup setTags call in reply-executor only passed slackUserName
  without slackUserId, so the if (context.slackUserId) guard in
  setSentryTagsFromContext was skipped and username was never set.

Fix:
- Add slackUserEmail to LogContext.
- Include email in setUser() and scope.setUser() calls.
- Consolidate the reply-executor setTags call to always pass slackUserId
  alongside slackUserName and slackUserEmail so the guard fires and all
  three fields land on the Sentry user object.

Co-Authored-By: Sergiy Dybskiy <sergiy@sentry.io>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 26, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
junior-docs Ready Ready Preview, Comment May 26, 2026 11:03pm

Request Review

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.

0 participants