Skip to content

Commit 2ce7fab

Browse files
JPeer264claude
andcommitted
test(e2e): Port cloudflare-mcp-agent to span streaming
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 3ac7e39 commit 2ce7fab

2 files changed

Lines changed: 23 additions & 33 deletions

File tree

‎dev-packages/e2e-tests/test-applications/cloudflare-mcp-agent/src/index.ts‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ class MyMCPAgentBase extends McpAgent<Env, unknown, Record<string, unknown>> {
5050

5151
export const MyMCPAgent = Sentry.instrumentDurableObjectWithSentry(
5252
(env: Env) => ({
53-
traceLifecycle: 'static',
5453
dsn: env.E2E_TEST_DSN,
5554
environment: 'qa',
5655
tunnel: `http://localhost:3031/`,
@@ -71,7 +70,6 @@ export const MyMCPAgent = Sentry.instrumentDurableObjectWithSentry(
7170

7271
export default Sentry.withSentry(
7372
(env: Env) => ({
74-
traceLifecycle: 'static',
7573
dsn: env.E2E_TEST_DSN,
7674
environment: 'qa',
7775
tunnel: `http://localhost:3031/`,

‎dev-packages/e2e-tests/test-applications/cloudflare-mcp-agent/tests/index.test.ts‎

Lines changed: 23 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,9 @@
11
import { expect, test } from '@playwright/test';
2-
import { waitForRequest } from '@sentry-internal/test-utils';
2+
import { waitForStreamedSpan } from '@sentry-internal/test-utils';
33

44
test('sends spans for MCP tool calls via MCPAgent (DurableObject)', async ({ baseURL }) => {
55
const privateMessage = 'cloudflare-agent-private-capture-policy-message';
6-
const mcpToolWaiter = waitForRequest('cloudflare-mcp-agent', event => {
7-
const transaction = event.envelope[1][0][1];
8-
return (
9-
typeof transaction !== 'string' &&
10-
'transaction' in transaction &&
11-
transaction.transaction === 'tools/call my-tool'
12-
);
13-
});
6+
const mcpSpanPromise = waitForStreamedSpan('cloudflare-mcp-agent', span => span.name === 'tools/call my-tool');
147

158
// Step 1: Initialize the MCP session
169
const initResponse = await fetch(`${baseURL}/mcp`, {
@@ -76,30 +69,29 @@ test('sends spans for MCP tool calls via MCPAgent (DurableObject)', async ({ bas
7669
expect(response.status).toBe(200);
7770
await expect(response.text()).resolves.toContain(`Tool my-tool: ${privateMessage}`);
7871

79-
const mcpData = await mcpToolWaiter;
80-
const mcpEvent = mcpData.envelope[1][0][1];
81-
const traceData = mcpEvent.contexts?.trace?.data;
72+
const mcpSpan = await mcpSpanPromise;
8273

83-
expect(mcpEvent.contexts?.trace?.trace_id).toBe(mcpData.envelope[0].trace.trace_id);
84-
expect(mcpEvent.contexts?.trace).toEqual({
85-
trace_id: expect.any(String),
86-
parent_span_id: expect.any(String),
87-
span_id: expect.any(String),
88-
op: 'mcp.server',
89-
origin: 'auto.function.mcp_server',
74+
expect(mcpSpan).toEqual({
75+
trace_id: expect.stringMatching(/^[a-f0-9]{32}$/),
76+
parent_span_id: expect.stringMatching(/^[a-f0-9]{16}$/),
77+
span_id: expect.stringMatching(/^[a-f0-9]{16}$/),
78+
name: 'tools/call my-tool',
79+
start_timestamp: expect.any(Number),
80+
end_timestamp: expect.any(Number),
9081
status: 'ok',
91-
data: expect.objectContaining({
92-
'sentry.origin': 'auto.function.mcp_server',
93-
'sentry.op': 'mcp.server',
94-
'mcp.method.name': 'tools/call',
95-
'mcp.tool.name': 'my-tool',
96-
'mcp.tool.extra': 'from-mcpagent',
97-
'mcp.tool.result.content_count': 1,
98-
'mcp.tool.result.content_type': 'text',
82+
is_segment: true,
83+
attributes: expect.objectContaining({
84+
'sentry.origin': { value: 'auto.function.mcp_server', type: 'string' },
85+
'sentry.op': { value: 'mcp.server', type: 'string' },
86+
'mcp.method.name': { value: 'tools/call', type: 'string' },
87+
'mcp.tool.name': { value: 'my-tool', type: 'string' },
88+
'mcp.tool.extra': { value: 'from-mcpagent', type: 'string' },
89+
'mcp.tool.result.content_count': { value: 1, type: 'integer' },
90+
'mcp.tool.result.content_type': { value: 'text', type: 'string' },
9991
}),
10092
});
101-
expect(traceData?.['mcp.request.argument.message']).toBeUndefined();
102-
expect(traceData?.['mcp.tool.result.content']).toBeUndefined();
103-
expect(traceData?.['mcp.tool.input']).toBeUndefined();
104-
expect(JSON.stringify(traceData)).not.toContain(privateMessage);
93+
expect(mcpSpan.attributes['mcp.request.argument.message']).toBeUndefined();
94+
expect(mcpSpan.attributes['mcp.tool.result.content']).toBeUndefined();
95+
expect(mcpSpan.attributes['mcp.tool.input']).toBeUndefined();
96+
expect(JSON.stringify(mcpSpan.attributes)).not.toContain(privateMessage);
10597
});

0 commit comments

Comments
 (0)