File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -624,6 +624,7 @@ export async function handleUnifiedChatPost(req: NextRequest) {
624624 return createUnauthorizedResponse ( )
625625 }
626626 const authenticatedUserId = session . user . id
627+ const authenticatedUserEmail = session . user . email
627628
628629 const body = ChatMessageSchema . parse ( await req . json ( ) )
629630 const normalizedContexts = normalizeContexts ( body . contexts ) ?? [ ]
@@ -639,6 +640,16 @@ export async function handleUnifiedChatPost(req: NextRequest) {
639640 if ( otelRoot . requestId ) {
640641 requestId = otelRoot . requestId
641642 }
643+ // Identity stamp — Go already stamps `user.id` on spans from the
644+ // validated API-key path, but Sim is the only side of the wire
645+ // that knows the human-facing email. Stamping both on the Sim
646+ // root (so they show up on `rootAttrs` in Tempo search) saves
647+ // the "turn user.id into a real person" round-trip to the DB
648+ // for every ad-hoc investigation.
649+ otelRoot . span . setAttribute ( TraceAttr . UserId , authenticatedUserId )
650+ if ( authenticatedUserEmail ) {
651+ otelRoot . span . setAttribute ( TraceAttr . UserEmail , authenticatedUserEmail )
652+ }
642653 // `setInputMessages` is internally gated on
643654 // OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT; safe to call.
644655 otelRoot . setInputMessages ( { userMessage : body . message } )
You can’t perform that action at this time.
0 commit comments