Repository navigation
feat(core): Inject trace context into outgoing MCP server messages - #26311
Draft
sentry-junior[bot] wants to merge 2 commits into
Draft
sentry-junior[bot] wants to merge 2 commits into
sentry-junior[bot] wants to merge 2 commits into
Conversation
Co-Authored-By: Francesco Gringl-Novy <francesco.novy@sentry.io>
sentry-junior
Bot
force-pushed
the
feat/mcp-server-inject-meta-trace
branch
from
November 12, 2026 08:12
740f240 to
fa2456a
Compare
Contributor
Optional E2E testsSome optional checks were not successful. They do not block the merge. 4 not successful, 53 successful. See the run.
Successful checks
|
Contributor
size-limit report 📦Compared: d19746c (PR test merge using develop at b248a87) Against: 480d930 (develop) · base run #65783
|
This branch has not been deployed
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.
Stacked on #26308.
Why: #26308 continues traces from
params._metaon incoming messages. This adds the other direction. Server-to-client requests (sampling, elicitation, roots, ping) and notifications (progress, logging, ...) now carrysentry-traceandbaggageinparams._meta, plustraceparentwhenpropagateTraceparentis enabled (the same opt-in as for HTTP). That lets a client link its handling back to the tool call that triggered it. Requests are parented to the active span, which inside a handler is thetools/callspan. Notifications are parented to their ownmcp.notification.server_to_clientspan.Messages that already carry
sentry-traceortraceparent, or whose_metaisn't an object, go through untouched, so we never overwrite context someone else set. The message is copied rather than mutated, because callers can reuse the object. Responses are left alone, since the spec only defines propagation for requests and notifications.How to review: Start with
injectMcpTraceContextintracePropagation.ts, then its two call sites inwrapTransportSend. The node integration test has an uninstrumented client continue the trace from what it received, which proves_metasurvives the real MCP SDK. The mock clients intestUtils.tsnow havegetTransport, becausegetTraceDatareads it throughisEnabled().Unsure about: Out of scope: MCP client instrumentation, which would inject on client-to-server requests.
via Francesco Gringl-Novy.
--
View Session [Sentry]