Skip to content

feat(core): Continue MCP server traces from params._meta - #26308

Merged
isaacs merged 6 commits into
developfrom
feat/mcp-server-meta-trace-propagation
Nov 17, 2026
Merged

isaacs merged 6 commits into
developfrom
feat/mcp-server-meta-trace-propagation

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

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. the http.server span 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 + baggage in _meta always continue the trace. W3C traceparent is only read when propagateTraceparent is enabled, matching how the SDK treats W3C elsewhere: opt-in, and with no default continuation from incoming traceparent. Malformed values fall back to today's behavior instead of starting a fresh trace. The W3C → sentry-trace converter 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/client to make sure _meta survives end to end.

Unsure about:

  • On Streamable HTTP, when the client injects _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.
  • With default options, OTel-only clients that send just traceparent won't connect until users set propagateTraceparent: true.
  • The link has no sentry.link.type, because none of the defined values fit a transport relationship.

Closes #17152

via Francesco Gringl-Novy.

--

View Session [Sentry]

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

size-limit report 📦

Compared: 36242a0 (PR test merge using develop at 429293d)

Against: ff1ae8a (develop) · base run #66567

⚠️ Baseline mismatch: 2 develop commit(s) in the PR build are missing from the baseline. Their size changes also affect this comparison. Compare commits. Re-run once develop's baseline build for 429293d finishes.

Path Size % Change Change
@sentry/browser 30.18 kB - -
@sentry/browser - with treeshaking flags 28.37 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 28.28 kB - -
@sentry/browser (incl. Tracing) 52.74 kB - -
@sentry/browser (incl. Tracing Core) 40.27 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 52.75 kB - -
@sentry/browser (incl. Tracing, Profiling) 55.63 kB - -
@sentry/browser (incl. Tracing, Replay) 92.79 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 81.61 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 97.16 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 110.39 kB - -
@sentry/browser (incl. Feedback) 47.8 kB - -
@sentry/browser (incl. sendFeedback) 30.76 kB - -
@sentry/browser (incl. FeedbackAsync) 35.76 kB - -
@sentry/browser (incl. Metrics) 31.5 kB - -
@sentry/browser (incl. Logs) 31.78 kB - -
@sentry/browser (incl. Metrics & Logs) 32.44 kB - -
@sentry/react 32.19 kB - -
@sentry/react (incl. Tracing) 55.39 kB - -
@sentry/vue 38.38 kB - -
@sentry/vue (incl. Tracing) 55.69 kB - -
@sentry/svelte 30.19 kB - -
@sentry/remix (Remix 3 client bundle) 58.4 kB - -
CDN Bundle 32.11 kB - -
CDN Bundle (incl. Tracing) 53.15 kB - -
CDN Bundle (incl. Logs, Metrics) 34.89 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 55.71 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 75.92 kB - -
CDN Bundle (incl. Tracing, Replay) 91.03 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 93.65 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 96.42 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 98.98 kB - -
CDN Bundle - uncompressed 93.8 kB - -
CDN Bundle (incl. Tracing) - uncompressed 157.13 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 102.13 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 164.75 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 232.25 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 277.28 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 284.91 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 289.07 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 296.69 kB - -
@sentry/nextjs (client) 59.02 kB - -
@sentry/sveltekit (client) 54.03 kB - -
@sentry/core/server 45.04 kB +0.55% +242 B 🔺
@sentry/core/browser 14.4 kB - -
@sentry/node 152.01 kB +0.18% +269 B 🔺
@sentry/node/import (ESM hook with diagnostics-channel injection) 83.34 kB - -
@sentry/node - without tracing 88.67 kB -0.01% -3 B 🔽
@sentry/node - without channel injection 140.94 kB +0.17% +238 B 🔺
@sentry/aws-serverless 99.04 kB -0.01% -1 B 🔽
@sentry/cloudflare (withSentry) - minified 206.95 kB - -
@sentry/cloudflare (withSentry) 480.37 kB - -
@sentry/nextjs/cloudflare (withSentry) - minified 232.31 kB - -

View base workflow run

@github-actions

github-actions Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Optional E2E tests

Some optional checks were not successful. They do not block the merge. 1 not successful, 62 successful. See the run.

Check Status
❌ CI: Optional E2E Tests / E2E nextjs-16-cacheComponents (cloudflare) Test (optional) Failing after 10m Details
Successful checks
Check Status
✅ CI: Optional E2E Tests / E2E cloudflare-pi-durable Test (optional) Successful in 57s Details
✅ CI: Optional E2E Tests / E2E nextjs-14 (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E debug-id-sourcemaps Test (optional) Successful in 39s Details
✅ CI: Optional E2E Tests / E2E deno (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-15 (latest) Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E nestjs-12 (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E astro-7-static Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-eve Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-fastify-6 Test (optional) Successful in 30s Details
✅ CI: Optional E2E Tests / E2E node-eve (orchestrion) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E cloudflare-pi-durable (latest) Test (optional) Successful in 49s Details
✅ CI: Optional E2E Tests / E2E node-flue Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nestjs-12 (deno) Test (optional) Successful in 52s Details
✅ CI: Optional E2E Tests / E2E node-express-mcp-v2 Test (optional) Successful in 35s Details
✅ CI: Optional E2E Tests / E2E gen-ai-libraries (cloudflare) Test (optional) Successful in 41s Details
✅ CI: Optional E2E Tests / E2E gen-ai-libraries Test (optional) Successful in 52s Details
✅ CI: Optional E2E Tests / E2E cloudflare-flue-send-to-sentry Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E node-express-send-to-sentry-static Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (vinext, bun) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-orpc Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E cloudflare-mastra Test (optional) Successful in 39s Details
✅ CI: Optional E2E Tests / E2E astro-7 Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-pi-durable Test (optional) Successful in 36s Details
✅ CI: Optional E2E Tests / E2E cloudflare-workers-send-to-sentry Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (client source maps kept) Test (optional) Successful in 36s Details
✅ CI: Optional E2E Tests / E2E nestjs-12 (cloudflare) Test (optional) Successful in 41s Details
✅ CI: Optional E2E Tests / E2E nextjs-16-tunnel (cloudflare) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-openai-decisions (latest) Test (optional) Successful in 37s Details
✅ CI: Optional E2E Tests / E2E cloudflare-workers-without-tracing-send-to-sentry Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E cloudflare-think Test (optional) Successful in 56s Details
✅ CI: Optional E2E Tests / E2E cloudflare-agent Test (optional) Successful in 46s Details
✅ CI: Optional E2E Tests / E2E react-router-7-framework-instrumentation Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (cloudflare, latest) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-cloudflare Test (optional) Successful in 39s Details
✅ CI: Optional E2E Tests / E2E gen-ai-libraries (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-eve (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nextjs-15 (turbo) Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nextjs-16 (vinext) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-mastra (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps (static / nuxt generate) Test (optional) Successful in 35s Details
✅ CI: Optional E2E Tests / E2E cloudflare-think (ai v6) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-express-mcp-v1 Test (optional) Successful in 33s Details
✅ CI: Optional E2E Tests / E2E nestjs-12 (bun) Test (optional) Successful in 58s Details
✅ CI: Optional E2E Tests / E2E node-eve (content off, latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-express-send-to-sentry Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-sourcemaps Test (optional) Successful in 41s Details
✅ CI: Optional E2E Tests / E2E supabase-nextjs Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nuxt-5 Test (optional) Successful in 2m Details
✅ CI: Optional E2E Tests / E2E nuxt-5-cloudflare Test (optional) Successful in 28s Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react-sourcemaps Test (optional) Successful in 31s Details
✅ CI: Optional E2E Tests / E2E nuxt-5 (kv-cache) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-pi-durable (latest) Test (optional) Successful in 37s Details
✅ CI: Optional E2E Tests / E2E solidstart-2-tunnel Test (optional) Successful in 44s Details
✅ CI: Optional E2E Tests / E2E nuxt-5-tunnel Test (optional) Successful in 49s Details
✅ CI: Optional E2E Tests / E2E node-mastra Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-flue (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E tanstackstart-react (latest) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-openai-decisions Test (optional) Successful in 28s Details
✅ CI: Optional E2E Tests / E2E vue-3 (no Options API) Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E solidstart-2 Test (optional) Successful in 57s Details
✅ CI: Optional E2E Tests / E2E react-send-to-sentry Test (optional) Successful in 3m Details
✅ CI: Optional E2E Tests / E2E nuxt-5 (development) Test (optional) Successful in 1m Details

@mydea mydea self-assigned this Nov 12, 2026
Comment thread packages/core/src/utils/tracing.ts Resolved
@sentry-junior
sentry-junior Bot added this pull request to stack #26312 November 12, 2026 08:10
@mydea
mydea marked this pull request as ready for review November 12, 2026 09:01
@mydea
mydea requested a review from a team November 12, 2026 09:02
@mydea
mydea requested a review from a team as a code owner November 12, 2026 09:02

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ 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.

@sentry-junior
sentry-junior Bot force-pushed the feat/mcp-server-meta-trace-propagation branch 2 times, most recently from 23ac367 to 97c2f00 Compare November 13, 2026 06:49

@isaacs isaacs 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.

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.

sentry-junior Bot and others added 6 commits November 17, 2026 18:09
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>
@sentry-junior
sentry-junior Bot force-pushed the feat/mcp-server-meta-trace-propagation branch from a559a3b to dc27d5f Compare November 17, 2026 18:11
@isaacs
isaacs enabled stacked auto-merge (squash) November 17, 2026 18:27
@isaacs
isaacs merged commit 452f91e into develop Nov 17, 2026
475 of 476 checks passed
@isaacs
isaacs deleted the feat/mcp-server-meta-trace-propagation branch November 17, 2026 18:31
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.

MCP Server - Trace propagation

3 participants