feat(server-utils): Auto-instrument MCP servers via orchestrion - #24529
Merged
Merged
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit e0e1545. Configure here.
Contributor
size-limit report 📦
|
mydea
added this pull request to stack #24534
September 21, 2026 08:30
mydea
marked this pull request as ready for review
September 21, 2026 09:05
mydea
requested review from
JPeer264,
betegon,
isaacs,
nicohrubec and
s1gr1d
and removed request for
a team
September 21, 2026 09:05
Contributor
|
👋 @isaacs, @JPeer264, @betegon, @nicohrubec, @s1gr1d, @getsentry/team-javascript-sdks — Please review this PR when you get a chance! |
JPeer264
approved these changes
Sep 24, 2026
JPeer264
left a comment
Member
There was a problem hiding this comment.
Nice addition (only the Node SDK size increases with these additions would be tough over time)
mydea
force-pushed
the
feat/mcp-server-auto-instrumentation
branch
3 times, most recently
from
September 28, 2026 08:36
3030fde to
b400ac4
Compare
Add an `mcpServer` integration that wraps `McpServer` instances at construction through an orchestrion constructor hook, so users no longer need to call `wrapMcpServerWithSentry` by hand. Covers both `@modelcontextprotocol/server` (v2, matched in its content-hashed chunk) and `@modelcontextprotocol/sdk` (v1). `wrapMcpServerWithSentry` stays a supported, idempotent no-op when the instance was already auto-wrapped. Rename the existing manual node-integration-test suite to `mcp-server/manual-instrumentation` and add `mcp-server/v1` and `mcp-server/v2` suites that exercise the auto-wrapping path. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Auto-instrumentation wraps each `McpServer` at construction with no explicit
capture options. The double-wrap guard previously ignored a later manual
`wrapMcpServerWithSentry(server, { recordInputs, recordOutputs })` entirely,
silently dropping the override so tool I/O could still be collected against a
server the user meant to opt out.
Track the mutable capture options per server (WeakMap) instead of a plain
WeakSet: a re-wrap now fills in options the first wrap left unset, so an
auto-wrap's defaults yield to a later manual override, while an explicit first
wrap still wins (unchanged, per `snapshots explicit overrides from the first
wrap`). The transport reads these options per message, so the update applies to
subsequent requests.
Also export `mcpServerIntegration` from the runtime packages that surface the
other tracing integrations (node, bun, deno, elysia, aws/gcp serverless,
astro), alongside `mastraIntegration`.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Making `mcpServerIntegration` a default (tracing) integration pulls the `wrapMcpServerWithSentry` instrumentation tree (~8.7 KB gzipped) into the `init` path, which was previously tree-shaken out. Bump the two affected `@sentry/node` scenarios to their measured sizes: - `@sentry/node`: 135 -> 139 KB - `@sentry/node - without channel injection`: 114 -> 117 KB `@sentry/node - without tracing` is unchanged (the integration is tracing-only). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add two Express e2e apps that construct an `McpServer` WITHOUT calling `wrapMcpServerWithSentry`, exercising the `mcpServer` integration's auto-wrapping over a real streamable-HTTP transport: - `node-express-mcp-v1-auto` (`@modelcontextprotocol/sdk` v1) - `node-express-mcp-v2-auto` (`@modelcontextprotocol/server` v2) Both assert the expected `mcp.server` spans (initialize, tool call, resource read, error status) still appear without a manual wrap. Bun/Deno/Cloudflare variants are intentionally left as a follow-up. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Drop the `-auto` suffix now that auto-instrumentation is the default path: - `node-express-mcp-v1-auto` -> `node-express-mcp-v1` - `node-express-mcp-v2-auto` -> `node-express-mcp-v2`, replacing the previous manual-wrap app of that name (same assertions, now exercising the default auto path). Manual-wrap coverage remains via the cloudflare-mcp apps and the v1 `node-express*` apps. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The MCP server suites were restructured into `mcp-server/manual-instrumentation`, `mcp-server/v1`, and `mcp-server/v2`, where v1/v2 rely on orchestrion auto-instrumentation. `bun run` cannot inject the diagnostics channels, so those suites produce no spans and fail. Replace the stale `mcp-server-streamed` exclude with a `mcp-server/**` glob covering all three. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
…egration The default `mcpServer` integration pushed the main `@sentry/node` entry to 141.21 KB, over its 139 KB limit. Bump to 142 KB. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
mydea
force-pushed
the
feat/mcp-server-auto-instrumentation
branch
from
September 28, 2026 09:22
b400ac4 to
06faed4
Compare
andreiborza
added a commit
that referenced
this pull request
Sep 28, 2026
…ntegration (#24797) ## What The MCP server integration now uses the shared diagnostics channel wrappers, so its subscription stays alive on Bun. ## Why #24529 and #24632 merged at the same time, and the direct `node:diagnostics_channel` import now fails lint on `develop` and on the 11.1.0 release PR. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
47 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.

McpServerinstances currently only produce spans when the user manually callswrapMcpServerWithSentry. This adds anmcpServerintegration (default, tracing) that wraps everyMcpServerat construction through an orchestrion constructor hook, so no manual call is needed.Both SDK families are covered:
@modelcontextprotocol/server(v2) — whoseMcpServerlives in a content-hashed tsdown chunk, so it's matched by a regexfilePathwithclassName: 'McpServer'as the real selector, the same shapemastra.tsuses — and@modelcontextprotocol/sdk(v1). The subscriber just hands the constructed instance to the existingwrapMcpServerWithSentry, reusing all of its transport/handler instrumentation rather than reimplementing anything.wrapMcpServerWithSentrystays fully supported. Re-wrapping an already-wrapped instance never patches it twice, but capture options are tracked per server (WeakMap): a later call fills inrecordInputs/recordOutputsleft unset by an earlier wrap. So the auto-wrap's defaults yield to a later manual override — a user can stillwrapMcpServerWithSentry(server, { recordInputs: false })to opt out — while an explicit first wrap still wins. The transport reads these options per message.mcpServerIntegrationis re-exported from the runtime packages that surface the other tracing integrations (node, bun, deno, elysia, aws/gcp serverless, astro), alongsidemastraIntegration.🤖 Generated with Claude Code