fix: conversation id override for baggage span processor#213
Merged
Conversation
jeanscherf
reviewed
Jul 7, 2026
jeanscherf
approved these changes
Jul 7, 2026
jeanscherf
left a comment
Member
There was a problem hiding this comment.
![]()
Added a suggestion but not a blocker
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.
Description
gen_ai.conversation.idwas inconsistent across spans when usingauto_instrument()with a LangGraph agent. The root cause: theopentelemetry-instrumentation-langchaincallback handler callsspan.set_attribute("gen_ai.conversation.id", thread_id)mid-span, afteron_startprocessors have already run, overwriting the caller-supplied value from the W3C baggage header.The fix replaces the third-party
opentelemetry-processor-baggagedependency with a built-inBaggageSpanProcessorthat adds anon_endoverride mechanism. For keys in an allowlist(
gen_ai.conversation.idby default), the baggage value is snapshotted aton_start(the only point the OTel context is live) and re-applied tospan._attributesaton_end, after all frameworkcallbacks have had their turn. All other baggage keys behave identically to before.
The two processor files are also moved into a
span_processors/subfolder for better organisation. This is an internal restructuring with no impact on the public API.Related Issue
Closes #157
Type of Change
Please check the relevant option:
How to Test
Describe how reviewers can test your changes:
auto_instrument()and injectgen_ai.conversation.idin the W3C baggage header on the incoming requestinvoke_agentLangGraph span — carry the samegen_ai.conversation.idvalue that was injected by the calling system, not the LangGraph thread IDChecklist
Before submitting your PR, please review and check the following: