fix: prefer W3C baggage conversation ID for span consistency#158
Open
handsomesix wants to merge 1 commit into
Open
fix: prefer W3C baggage conversation ID for span consistency#158handsomesix wants to merge 1 commit into
handsomesix wants to merge 1 commit into
Conversation
|
|
When using LangGraph with traceloop, the invoke_agent span gets a different gen_ai.conversation.id than the one propagated via W3C baggage header, because traceloop derives it from thread_id. Add _resolve_conversation_id() that applies priority: 1. Explicit conversation_id parameter (highest) 2. W3C baggage gen_ai.conversation.id 3. None Apply to both chat_span and invoke_agent_span so all spans in a trace share the same conversation ID. Fixes SAP#157
7acc3b1 to
af0733e
Compare
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.
Summary
Fix inconsistent
gen_ai.conversation.idvalues between LangGraphinvoke_agentspans and other spans when using traceloop instrumentation.The change introduces a shared conversation ID resolution mechanism that prioritizes:
conversation_idparametergen_ai.conversation.idfrom W3C baggageThis ensures all spans within the same trace use a consistent conversation ID.
Root Cause
invoke_agentspans relied on traceloop-derived values, which are sourced fromthread_id.At the same time, SAP Cloud SDK propagates the conversation identifier through the W3C baggage header. When the traceloop
thread_idand baggage-provided conversation ID differ,invoke_agentspans receive a differentgen_ai.conversation.idthan the rest of the trace.As a result, spans belonging to the same conversation can be associated with different conversation identifiers.
Changes
_resolve_conversation_id()helper to centralize conversation ID resolution.conversation_idparametergen_ai.conversation.idchat_span.invoke_agent_span.Tests
Added unit tests covering
_resolve_conversation_id()behavior:conversation_idtakes precedence.Nonewhen baggage is not present.Nonewhen baggage value is empty.Risk
Low.
conversation_idbehavior is unchanged.