Extract trace context from MCP _meta for distributed tracing#3763
Merged
ChrisJBurns merged 7 commits intomainfrom Feb 11, 2026
Merged
Extract trace context from MCP _meta for distributed tracing#3763ChrisJBurns merged 7 commits intomainfrom
ChrisJBurns merged 7 commits intomainfrom
Conversation
- Fix SSE active connections gauge that was incremented but never decremented. Move increment into Handler with a defer decrement so the gauge correctly tracks SSE connection lifecycle. - Fix config file `use-legacy-attributes: false` being silently ignored. Change UseLegacyAttributes from bool to *bool in app config so nil (not set) is distinguishable from explicit false. Add two test cases covering both scenarios. - Log metric creation errors at debug level instead of silently discarding them. The OTEL SDK returns no-op instruments on error so there is no runtime risk, but logging aids troubleshooting. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ng, and client span kind
- Add mcp.protocol.version span attribute by reading the
MCP-Protocol-Version header from streamable HTTP requests.
- Add mcp.client.operation.duration histogram metric to vMCP backend
client using the OTEL MCP semconv bucket boundaries, alongside the
existing toolhive_vmcp_backend_requests_duration custom metric.
- Include target name in span names per OTEL MCP semconv. Span names
now follow the "{method} {target}" format, e.g. "tools/call
github_search" instead of just "tools/call".
- Set SpanKindClient on vMCP backend call spans for proper distributed
trace linking.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…le-http version - B3: Remove omitempty from TracingEnabled/MetricsEnabled struct tags so YAML `false` values are not silently dropped during serialization - B6: Move tool call counter from per-request creation to struct initialization in NewHTTPMiddleware for consistency with other counters - B10: Return empty string for streamable-http protocol version in mapTransport since the actual backend version is unknown - T1: Add SSE dual emission test verifying recordSSEConnection emits both new and legacy span attributes based on UseLegacyAttributes flag Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Per the MCP OTEL spec, servers should extract traceparent/tracestate from params._meta and use as parent span context. The MetaCarrier infrastructure already existed but was not wired into the middleware. After HTTP header extraction, the middleware now also extracts trace context from _meta if present. The _meta extraction takes priority since it is the MCP-specified propagation mechanism. Includes integration test verifying that a traceparent in _meta produces a child span with the correct parent trace/span IDs. Closes S1 from otel-remaining-work.md. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3763 +/- ##
==========================================
+ Coverage 66.44% 66.50% +0.06%
==========================================
Files 428 428
Lines 42087 42090 +3
==========================================
+ Hits 27965 27993 +28
+ Misses 11986 11961 -25
Partials 2136 2136 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
jhrozek
approved these changes
Feb 11, 2026
11 tasks
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
MetaCarrierinto the telemetry middleware to extracttraceparent/tracestatefrom MCPparams._meta, enabling distributed tracing per the MCP OTEL specMetaCarrierinfrastructure (from PR Add W3C Trace Context propagation via MCP _meta #3682) already existed but was not connected to the middleware's trace context extraction_metaif present —_metatakes priority as the MCP-specified propagation mechanismParent issue: #3399
Test plan
task test— all telemetry tests passtask lint— 0 issuesTestTelemetryIntegration_MetaTraceContextExtractionverifies:traceparentin_metaproduces a child span with the correct parent trace ID_metaSpanKindServer🤖 Generated with Claude Code