Skip to content

Commit 79d3e5b

Browse files
committed
Updates
1 parent a4949ff commit 79d3e5b

2 files changed

Lines changed: 1055 additions & 1042 deletions

File tree

apps/sim/lib/copilot/chat/post.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff 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 })

0 commit comments

Comments
 (0)