Repository navigation
feat(core): Continue MCP server traces from params._meta - #26308
Conversation
size-limit report 📦Compared: 36242a0 (PR test merge using develop at 429293d) Against: ff1ae8a (develop) · base run #66567
|
Optional E2E testsSome optional checks were not successful. They do not block the merge. 1 not successful, 62 successful. See the run.
Successful checks
|
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 799d383. Configure here.
23ac367 to
97c2f00
Compare
isaacs
left a comment
There was a problem hiding this comment.
The PR description correctly says that on Streamable HTTP, the MCP span moves out of the HTTP request's trace when the client sends _meta, and that this deserves a changelog line. I agree. Users who look at an HTTP request in Sentry will no longer see the MCP span as a child; they have to follow the link. The ## Unreleased section in CHANGELOG.md gets written at release time, so this needs a note for whoever writes it.
Suggestion: add a short "Important Changes" note for the release. It should say that MCP server spans now continue the caller's trace from params._meta, and that the transport span is linked, not the parent.
Fixes #17152 Co-Authored-By: Francesco Gringl-Novy <francesco.novy@sentry.io>
continueTrace starts a new trace when the incoming org ID does not match, or when strictTraceContinuation is on and one side lacks an org ID. That detached MCP spans from the HTTP request trace they joined before. Check shouldContinueTrace first and fall back to the current context.
MCP spans on Streamable HTTP move out of the HTTP request's trace when the client sends trace context in _meta, which users will notice. Co-Authored-By: Isaac Schlueter <isaac.schlueter@sentry.io>
a559a3b to
dc27d5f
Compare

Why: MCP clients propagate trace context per message in
params._meta(SEP-414, OTel MCP semconv), but our server instrumentation ignored it, so MCP server spans never connected to the calling agent's trace. Over stdio there was no other way to connect them at all. Incoming requests and notifications now continue the trace from_meta. The span that was active when the message arrived (e.g. thehttp.serverspan on Streamable HTTP) is added as a span link, which is what the semconv asks for, since MCP and transport contexts are independent.sentry-trace+baggagein_metaalways continue the trace. W3Ctraceparentis only read whenpropagateTraceparentis enabled, matching how the SDK treats W3C elsewhere: opt-in, and with no default continuation from incomingtraceparent. Malformed values fall back to today's behavior instead of starting a fresh trace. The W3C →sentry-traceconverter moved from the Flue integration into core so both can share it.How to review: Start with
packages/core/src/integrations/mcp-server/tracePropagation.ts. The transport and span changes just pass its result through. The node integration test uses the real@modelcontextprotocol/clientto make sure_metasurvives end to end.Unsure about:
_meta, the MCP span moves out of the HTTP request's trace into the caller's trace, and the HTTP span is only reachable via the link. That's spec behavior but a visible change, so it probably deserves a changelog line.traceparentwon't connect until users setpropagateTraceparent: true.sentry.link.type, because none of the defined values fit a transport relationship.Closes #17152
via Francesco Gringl-Novy.
--
View Session [Sentry]