Skip to content

Add W3C Trace Context propagation via MCP _meta#3682

Merged
ChrisJBurns merged 5 commits intomainfrom
otel/propagation-foundation
Feb 9, 2026
Merged

Add W3C Trace Context propagation via MCP _meta#3682
ChrisJBurns merged 5 commits intomainfrom
otel/propagation-foundation

Conversation

@ChrisJBurns
Copy link
Collaborator

@ChrisJBurns ChrisJBurns commented Feb 6, 2026

Summary

  • Add MetaCarrier implementing propagation.TextMapCarrier for MCP _meta fields
  • Add InjectMetaTraceContext for injecting traceparent/tracestate into outgoing MCP requests
  • Enable distributed tracing across vMCP → backend boundaries using standard W3C Trace Context format

This is the foundation layer for the MCP OTEL semantic conventions alignment (#3399). The propagation carrier and injection function are used by subsequent PRs to inject trace context into outgoing MCP calls.

PR Stack (1/3): This PR → #3683 (metrics/attributes) → #3 (client spans)

Test plan

  • Unit tests for MetaCarrier (Get/Set/Keys/Meta)
  • Unit tests for InjectMetaTraceContext (with real tracer, nil meta)
  • Tests that mutate global OTEL propagator are non-parallel (with //nolint directive)
  • go build ./... passes
  • go test ./pkg/telemetry/... passes
  • task lint-fix passes with 0 issues

🤖 Generated with Claude Code

Add MetaCarrier (TextMapCarrier for MCP _meta fields) and
InjectMetaTraceContext for injecting traceparent/tracestate
into outgoing MCP requests, per the MCP OTEL specification.

This enables distributed tracing across vMCP → backend boundaries
using the standard W3C Trace Context format propagated through
MCP params._meta.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@codecov
Copy link

codecov bot commented Feb 6, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 66.32%. Comparing base (2c00fae) to head (903fb98).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3682   +/-   ##
=======================================
  Coverage   66.31%   66.32%           
=======================================
  Files         426      427    +1     
  Lines       41742    41765   +23     
=======================================
+ Hits        27682    27700   +18     
- Misses      11948    11955    +7     
+ Partials     2112     2110    -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@jhrozek jhrozek left a comment

Choose a reason for hiding this comment

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

Review conducted with 4 specialized agents (MCP Protocol Expert, Go Expert Developer, Security Reviewer, Code Reviewer). 2 inline comments below, no blocking issues found.

Overall: Clean, correct, well-tested implementation. MCP spec-compliant use of _meta for W3C Trace Context. No security concerns.

@jhrozek
Copy link
Contributor

jhrozek commented Feb 9, 2026

@claude could you rebase the commit atop origin/main and see if you can address my review comments in a separate commit (they are squashed anyway and a separate commit will be easier to back away from)

@claude
Copy link
Contributor

claude bot commented Feb 9, 2026

Claude finished @jhrozek's task in 2m 24s —— View job


Review comments addressed ✓

  • Fetch latest from origin/main and rebase (already based on recent commit)
  • Read current test file to understand structure
  • Read propagation.go file
  • Refactor test to table-driven format
  • Add compile-time assertion for TextMapCarrier interface
  • Run tests to verify changes (all tests pass)
  • Commit changes as separate commit
  • Push to remote branch

Changes Made

I've successfully addressed both review comments in a separate commit (125f2d1):

  1. Added compile-time assertion (pkg/telemetry/propagation.go):

    // Compile-time assertion that MetaCarrier implements propagation.TextMapCarrier
    var _ propagation.TextMapCarrier = (*MetaCarrier)(nil)

    This ensures at compile time that MetaCarrier correctly implements the propagation.TextMapCarrier interface.

  2. Refactored to table-driven test (pkg/telemetry/propagation_test.go):

    • Converted the Get operations in TestMetaCarrier_GetSetKeys to use a table-driven test pattern with subtests
    • This makes the test more compact and easier to extend with additional test cases

All tests pass successfully. The linter check will run in CI since it requires tool approval.

--- | Branch: otel/propagation-foundation

- Add compile-time assertion that MetaCarrier implements propagation.TextMapCarrier
- Refactor TestMetaCarrier_GetSetKeys to use table-driven test pattern for Get operations

Co-authored-by: Jakub Hrozek <jhrozek@users.noreply.github.com>
@jhrozek
Copy link
Contributor

jhrozek commented Feb 9, 2026

welp, I don't know if the table-driven test is an improvement

jhrozek
jhrozek previously approved these changes Feb 9, 2026
@github-actions github-actions bot added size/S Small PR: 100-299 lines changed and removed size/S Small PR: 100-299 lines changed labels Feb 9, 2026
@ChrisJBurns
Copy link
Collaborator Author

@claude Address the lint errors that occur in the pipeline please

@claude
Copy link
Contributor

claude bot commented Feb 9, 2026

Claude finished @ChrisJBurns's task in 1m 13s —— View job


Lint errors fixed ✓

  • Check CI status to identify lint errors
  • Fix paralleltest/tparallel issues in pkg/telemetry/propagation_test.go
  • Commit and push changes

What was fixed:

  • Added t.Parallel() call to subtests in the table-driven test in TestMetaCarrier_GetSetKeys
  • This satisfies both the paralleltest and tparallel linters

Changes committed:

  • Commit: 9ec55e4
  • The lint errors should now be resolved in the CI pipeline

--- | | Branch: otel/propagation-foundation

- Added t.Parallel() call in subtests to satisfy paralleltest/tparallel linters
- Maintains test isolation while allowing parallel execution

Co-authored-by: Chris Burns <ChrisJBurns@users.noreply.github.com>
@github-actions github-actions bot added size/S Small PR: 100-299 lines changed and removed size/S Small PR: 100-299 lines changed labels Feb 9, 2026
@ChrisJBurns ChrisJBurns merged commit 0761277 into main Feb 9, 2026
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/S Small PR: 100-299 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants