fix(sentry): set user email and username on Sentry user context#418
Draft
sentry-junior[bot] wants to merge 1 commit into
Draft
fix(sentry): set user email and username on Sentry user context#418sentry-junior[bot] wants to merge 1 commit into
sentry-junior[bot] wants to merge 1 commit into
Conversation
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>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The Sentry AI Conversations view showed Slack's infrastructure IPs instead of human-readable user identifiers. Investigation confirmed two bugs:
Bug 1 —
usernamewas silently droppedsetSentryTagsFromContextonly callsSentry.setUser()whencontext.slackUserIdis present. The post-lookupsetTags({ slackUserName: resolvedUserName })call inreply-executor.tspassedslackUserNamewithoutslackUserId, so the guard was never satisfied andusernamewas never written to the Sentry user object.Bug 2 —
emailwas never plumbed to SentrylookupSlackUserfetchesprofile.emailfrom the Slack API, andreply-executoralready passesfallbackIdentity?.emailintogenerateAssistantReplyfor prompt context — but the field was missing fromLogContextand never reachedsetUser().Result: Sentry events had
user.id = <SlackId>butuser.username = nullanduser.email = null. The Conversations view fell back touser.ip, which captured Slack's egress IPs rather than the human user.Changes
logging.ts— AddslackUserEmail?: stringtoLogContext. Threademailinto bothSentry.setUser()(global scope) andscope.setUser()(per-exception scope).reply-executor.ts— Consolidate the post-lookupsetTagscall to always includeslackUserIdalongsideslackUserNameandslackUserEmail, so theif (context.slackUserId)guard fires and all three fields land on the Sentry user object in one shot.Verified
tsc --noEmit)Fixes attribution in the Sentry AI Conversations view — conversations will now show
user.email(from Slack profile) anduser.username(Slack display name) instead of infrastructure IPs.View Session in Sentry
Action taken on behalf of Sergiy Dybskiy.