From 662a432b9ef93cb1ead7d93f8b4759a7ae729a78 Mon Sep 17 00:00:00 2001 From: Ognjen Bostjancic Date: Thu, 25 Jun 2026 12:36:43 +0200 Subject: [PATCH] feat(agent-monitoring): Add setUser step to Conversations onboarding Add a guided 'Identify Users (optional)' step to the Conversations onboarding flow, parallel to the existing 'Set Conversation ID' step. This teaches users to call Sentry.setUser() (JS) or sentry_sdk.set_user() (Python) so the User column in the Conversations view is populated. Also mention setUser in the LLM_ONBOARDING_COPY_MARKDOWN prompt so AI coding agents include the call when setting up agent monitoring. Refs TET-2513 Co-Authored-By: Claude Sonnet 4 --- .../explore/conversations/onboarding.tsx | 34 +++++++++++++++++++ .../agents/llmOnboardingInstructions.tsx | 1 + 2 files changed, 35 insertions(+) diff --git a/static/app/views/explore/conversations/onboarding.tsx b/static/app/views/explore/conversations/onboarding.tsx index fd8ab8c8259b..3211db736500 100644 --- a/static/app/views/explore/conversations/onboarding.tsx +++ b/static/app/views/explore/conversations/onboarding.tsx @@ -273,6 +273,39 @@ Sentry.setConversationId("my-conversation-123");`, }; } +function getSetUserStep(isPython: boolean): OnboardingStep { + const content: ContentBlock[] = [ + { + type: 'text', + text: t( + 'Identify the user behind each conversation so the Conversations view can show who sent each message:' + ), + }, + isPython + ? { + type: 'code' as const, + language: 'python', + code: `import sentry_sdk + +# Call this once per request / session, before any AI calls +sentry_sdk.set_user({"id": "user_123", "email": "jane@example.com", "username": "jane"})`, + } + : { + type: 'code' as const, + language: 'javascript', + code: `import * as Sentry from "@sentry/node"; + +// Call this once per request / session, before any AI calls +Sentry.setUser({ id: "user_123", email: "jane@example.com", username: "jane" });`, + }, + ]; + + return { + title: t('Identify Users (optional)'), + content, + }; +} + export function ConversationOnboarding({onDismiss}: {onDismiss: () => void}) { const api = useApi(); const {isSelfHosted, urlPrefix} = useLegacyStore(ConfigStore); @@ -369,6 +402,7 @@ export function ConversationOnboarding({onDismiss}: {onDismiss: () => void}) { ...(agentMonitoringDocs.install?.(docParams) || []), ...(agentMonitoringDocs.configure?.(docParams) || []), getConversationIdStep(selectedIntegration, isPythonPlatform), + getSetUserStep(isPythonPlatform), ...(agentMonitoringDocs.verify?.(docParams) || []), ].filter(s => !s.collapsible); diff --git a/static/app/views/insights/pages/agents/llmOnboardingInstructions.tsx b/static/app/views/insights/pages/agents/llmOnboardingInstructions.tsx index f8a4623c9ff6..56cbdc43155e 100644 --- a/static/app/views/insights/pages/agents/llmOnboardingInstructions.tsx +++ b/static/app/views/insights/pages/agents/llmOnboardingInstructions.tsx @@ -70,6 +70,7 @@ export const LLM_ONBOARDING_COPY_MARKDOWN = ` > The setup steps above contain the correct DSN and project-specific SDK configuration — complete them first. > Then follow the skill references below for instrumentation and agent naming. > If the app has multi-turn chats, set a conversation ID for each chat so Sentry can send the gen_ai.conversation.id attribute and show the session in Conversations. +> Also call setUser (JS) / sentry_sdk.set_user (Python) once per request or session so conversations are attributed to users in the Conversations view. # Instrument Sentry AI Agent Monitoring