-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
feat(core): Emit low cardinality mcp.server span names #23569
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
andreiborza
merged 3 commits into
develop
from
ab/mcp-server-low-cardinality-span-names
Aug 26, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
9 changes: 9 additions & 0 deletions
9
dev-packages/node-integration-tests/suites/tracing/mcp-server-streamed/instrument.mjs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import * as Sentry from '@sentry/node'; | ||
| import { loggingTransport } from '@sentry-internal/node-integration-tests'; | ||
|
|
||
| Sentry.init({ | ||
| dsn: 'https://public@dsn.ingest.sentry.io/1337', | ||
| release: '1.0', | ||
| tracesSampleRate: 1.0, | ||
| transport: loggingTransport, | ||
| }); |
26 changes: 26 additions & 0 deletions
26
dev-packages/node-integration-tests/suites/tracing/mcp-server-streamed/scenario.mjs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| import { Client } from '@modelcontextprotocol/client'; | ||
| import { InMemoryTransport, McpServer, ResourceTemplate } from '@modelcontextprotocol/server'; | ||
| import { wrapMcpServerWithSentry } from '@sentry/node'; | ||
|
|
||
| const server = wrapMcpServerWithSentry(new McpServer({ name: 'Echo', version: '1.0.0' })); | ||
|
|
||
| server.registerResource('echo', new ResourceTemplate('echo://{message}', { list: undefined }), {}, async uri => ({ | ||
| contents: [{ uri: uri.href, text: 'Resource echo' }], | ||
| })); | ||
|
|
||
| server.registerTool('echo', {}, async () => ({ content: [{ type: 'text', text: 'Tool echo' }] })); | ||
|
|
||
| async function run() { | ||
| const [clientTransport, serverTransport] = InMemoryTransport.createLinkedPair(); | ||
| const client = new Client({ name: 'test-client', version: '1.0.0' }); | ||
|
|
||
| await Promise.all([server.connect(serverTransport), client.connect(clientTransport)]); | ||
|
|
||
| await client.readResource({ uri: 'echo://foobar' }); | ||
| await client.callTool({ name: 'echo', arguments: {} }); | ||
|
|
||
| await client.close(); | ||
| await server.close(); | ||
| } | ||
|
|
||
| run(); |
46 changes: 46 additions & 0 deletions
46
dev-packages/node-integration-tests/suites/tracing/mcp-server-streamed/test.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import type { SerializedStreamedSpanContainer } from '@sentry/core'; | ||
| import { afterAll, describe, expect } from 'vitest'; | ||
| import { cleanupChildProcesses, createEsmAndCjsTests } from '../../../utils/runner'; | ||
|
|
||
| function mcpSpans(container: SerializedStreamedSpanContainer): SerializedStreamedSpanContainer['items'] { | ||
| return container.items.filter(item => item.attributes['sentry.op']?.value === 'mcp.server'); | ||
| } | ||
|
|
||
| describe('MCP server spans (streamed)', () => { | ||
| afterAll(() => { | ||
| cleanupChildProcesses(); | ||
| }); | ||
|
|
||
| createEsmAndCjsTests(__dirname, 'scenario.mjs', 'instrument.mjs', (createTestRunner, test) => { | ||
| test('names resource spans after the method alone, keeping the URI on the attribute', async () => { | ||
| await createTestRunner() | ||
| .expect({ | ||
| span: container => { | ||
| const resourceSpan = mcpSpans(container).find( | ||
| span => span.attributes['mcp.method.name']?.value === 'resources/read', | ||
| ); | ||
|
|
||
| expect(resourceSpan?.name).toBe('resources/read'); | ||
| expect(resourceSpan?.attributes['mcp.resource.uri']?.value).toBe('echo://foobar'); | ||
| }, | ||
| }) | ||
| .start() | ||
| .completed(); | ||
| }); | ||
|
|
||
| test('keeps the tool name, which comes from a bounded registry', async () => { | ||
| await createTestRunner() | ||
| .expect({ | ||
| span: container => { | ||
| const toolSpan = mcpSpans(container).find( | ||
| span => span.attributes['mcp.method.name']?.value === 'tools/call', | ||
| ); | ||
|
|
||
| expect(toolSpan?.name).toBe('tools/call echo'); | ||
| }, | ||
| }) | ||
| .start() | ||
| .completed(); | ||
| }); | ||
|
andreiborza marked this conversation as resolved.
|
||
| }); | ||
| }); | ||
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
q: Is this pinned on purpose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This matches our other mcp apps, I just followed suite tbh. We could loosen it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense. Loosening it wouldn't be a bad idea though.- not a PR blocker
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do in a follow-up.