fix(tracing): seed log context before route-thinking to fix gen_ai.conversation.id on gen_ai.chat spans#613
Closed
dcramer wants to merge 1 commit into
Closed
fix(tracing): seed log context before route-thinking to fix gen_ai.conversation.id on gen_ai.chat spans#613dcramer wants to merge 1 commit into
dcramer wants to merge 1 commit into
Conversation
…nversation.id on gen_ai.chat spans
In the queue-worker path (POST /api/internal/agent/continue), spanContext
is computed before selectTurnThinkingLevel runs but is not yet installed
into AsyncLocalStorage. As a result, the gen_ai.chat span emitted by the
Haiku router call does not inherit gen_ai.conversation.id, violating OTel
GenAI semconv which marks that attribute Conditionally Required on all
gen_ai.chat spans.
The Slack inline path is unaffected because slack-runtime.ts wraps the
full turn in withSpan('chat.turn', ..., context) which seeds ALS with
conversationId before selectTurnThinkingLevel runs.
Fix: wrap the awaited selectTurnThinkingLevel call in withLogContext(spanContext)
so the route-thinking subtree (chat.route_thinking + its gen_ai.chat span)
inherits gen_ai.conversation.id in both execution paths.
Co-Authored-By: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Member
Author
|
Closing — the premise is wrong per OTel semconv. The router (Haiku) call is a one-shot classifier with no conversation context, so its |
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
In the queue-worker path (
POST /api/internal/agent/continue),gen_ai.conversation.idis missing from thegen_ai.chatspan emitted during thinking-level routing (the Haiku router call).OTel GenAI semconv marks
gen_ai.conversation.idas Conditionally Required ongen_ai.chatandgen_ai.invoke_agentspans. All othergen_ai.*spans in Junior already carry it — this was the one gap.Root cause
gen_ai.conversation.idpropagates via AsyncLocalStorage.spanContext(which hasconversationId) is computed beforeselectTurnThinkingLevelis called, but hasn't been installed into ALS yet at that point. So thechat.route_thinking+ its nestedgen_ai.chatspan both miss the attribute in queue-worker turns.The Slack inline path is unaffected:
slack-runtime.tswraps the full turn inwithSpan('chat.turn', ..., context)which seeds ALS withconversationIdbeforeselectTurnThinkingLevelruns.Fix
Wrap the awaited
selectTurnThinkingLevelcall inwithLogContext(spanContext, ...). This is a scoped seed — it only covers the route-thinking subtree, leaves everything else unchanged, and works identically in both code paths.Verification
After this change, in queue-worker turns:
chat.route_thinkinghasgen_ai.conversation.id✓gen_ai.chatinside route-thinking hasgen_ai.conversation.id✓View Session in Sentry