From 85a166aa6593392d891c9bf64d0a21a94a99ce56 Mon Sep 17 00:00:00 2001 From: "sentry-junior[bot]" <264270552+sentry-junior[bot]@users.noreply.github.com> Date: Tue, 26 May 2026 23:02:39 +0000 Subject: [PATCH] fix(sentry): set user email and username on Sentry user context 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 --- packages/junior/src/chat/logging.ts | 8 +++++++- packages/junior/src/chat/runtime/reply-executor.ts | 8 +++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/junior/src/chat/logging.ts b/packages/junior/src/chat/logging.ts index 040e0277..fbd64a20 100644 --- a/packages/junior/src/chat/logging.ts +++ b/packages/junior/src/chat/logging.ts @@ -36,6 +36,7 @@ export interface LogContext { slackThreadId?: string; slackUserId?: string; slackUserName?: string; + slackUserEmail?: string; slackChannelId?: string; runId?: string; assistantUserName?: string; @@ -1375,6 +1376,7 @@ export function setSentryTagsFromContext(context: LogContext): void { Sentry.setUser({ id: context.slackUserId, username: context.slackUserName, + email: context.slackUserEmail, }); } } @@ -1390,7 +1392,11 @@ export function setSentryScopeContext( } } if (context.slackUserId) { - scope.setUser({ id: context.slackUserId, username: context.slackUserName }); + scope.setUser({ + id: context.slackUserId, + username: context.slackUserName, + email: context.slackUserEmail, + }); } scope.setContext("app", attrs); } diff --git a/packages/junior/src/chat/runtime/reply-executor.ts b/packages/junior/src/chat/runtime/reply-executor.ts index a614bc09..3757b753 100644 --- a/packages/junior/src/chat/runtime/reply-executor.ts +++ b/packages/junior/src/chat/runtime/reply-executor.ts @@ -432,9 +432,11 @@ export function createReplyToThread(deps: ReplyExecutorDeps) { ); const resolvedUserName = message.author.userName ?? fallbackIdentity?.userName; - if (resolvedUserName) { - setTags({ slackUserName: resolvedUserName }); - } + setTags({ + slackUserId: message.author.userId, + slackUserName: resolvedUserName, + slackUserEmail: fallbackIdentity?.email, + }); const userAttachments = await deps.resolveUserAttachments( message.attachments, {