Skip to content

fix: conversation id override for baggage span processor#213

Merged
LucasAlvesSoares merged 4 commits into
mainfrom
baggage-span-processor
Jul 7, 2026
Merged

fix: conversation id override for baggage span processor#213
LucasAlvesSoares merged 4 commits into
mainfrom
baggage-span-processor

Conversation

@LucasAlvesSoares

@LucasAlvesSoares LucasAlvesSoares commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Description

gen_ai.conversation.id was inconsistent across spans when using auto_instrument() with a LangGraph agent. The root cause: the opentelemetry-instrumentation-langchain callback handler calls
span.set_attribute("gen_ai.conversation.id", thread_id) mid-span, after on_start processors have already run, overwriting the caller-supplied value from the W3C baggage header.

The fix replaces the third-party opentelemetry-processor-baggage dependency with a built-in BaggageSpanProcessor that adds an on_end override mechanism. For keys in an allowlist
(gen_ai.conversation.id by default), the baggage value is snapshotted at on_start (the only point the OTel context is live) and re-applied to span._attributes at on_end, after all framework
callbacks 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:

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update
  • Code refactoring
  • Dependency update

How to Test

Describe how reviewers can test your changes:

  1. Run a LangGraph agent with auto_instrument() and inject gen_ai.conversation.id in the W3C baggage header on the incoming request
  2. Inspect the exported trace spans
  3. Expected result: all spans — including the invoke_agent LangGraph span — carry the same gen_ai.conversation.id value that was injected by the calling system, not the LangGraph thread ID

Checklist

Before submitting your PR, please review and check the following:

  • I have read the Contributing Guidelines
  • I have verified that my changes solve the issue
  • I have added/updated automated tests to cover my changes
  • All tests pass locally
  • I have verified that my code follows the Code Guidelines
  • I have updated documentation (if applicable)
  • I have added type hints for all public APIs
  • My code does not contain sensitive information (credentials, tokens, etc.)
  • I have followed Conventional Commits for commit messages

@LucasAlvesSoares LucasAlvesSoares marked this pull request as ready for review July 7, 2026 16:07
@LucasAlvesSoares LucasAlvesSoares requested a review from a team as a code owner July 7, 2026 16:07

@jeanscherf jeanscherf left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

Added a suggestion but not a blocker

@LucasAlvesSoares LucasAlvesSoares merged commit c232dc0 into main Jul 7, 2026
11 checks passed
@LucasAlvesSoares LucasAlvesSoares deleted the baggage-span-processor branch July 7, 2026 20:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Found different gen_ai.conversation.id value in invoke_agent LangGraph span

2 participants