Skip to content

Commit 4e5cb9b

Browse files
committed
fix test app
1 parent b6ce670 commit 4e5cb9b

File tree

7 files changed

+21
-37
lines changed

7 files changed

+21
-37
lines changed

dev-packages/e2e-tests/test-applications/tsx-express/instrument.mjs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,8 @@ import * as Sentry from '@sentry/node';
33
Sentry.init({
44
environment: 'qa', // dynamic sampling bias to keep transactions
55
dsn: process.env.E2E_TEST_DSN,
6-
includeLocalVariables: true,
76
debug: !!process.env.DEBUG,
87
tunnel: `http://localhost:3031/`, // proxy server
98
tracesSampleRate: 1,
10-
_experiments: {
11-
enableLogs: true,
12-
},
9+
enableLogs: true,
1310
});

dev-packages/e2e-tests/test-applications/tsx-express/src/app.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,8 @@ export const appRouter = t.router({
119119
.mutation(() => {
120120
throw new Error('I crashed in a trpc handler');
121121
}),
122-
unauthorized: procedure.mutation(() => {
123-
throw new TRPCError({ code: 'UNAUTHORIZED', cause: new Error('Unauthorized') });
122+
badRequest: procedure.mutation(() => {
123+
throw new TRPCError({ code: 'BAD_REQUEST', cause: new Error('Bad Request') });
124124
}),
125125
});
126126

dev-packages/e2e-tests/test-applications/tsx-express/tests/errors.test.ts

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,3 @@ test('Sends correct error event', async ({ baseURL }) => {
2727
span_id: expect.stringMatching(/[a-f0-9]{16}/),
2828
});
2929
});
30-
31-
test('Should record caught exceptions with local variable', async ({ baseURL }) => {
32-
const errorEventPromise = waitForError('tsx-express', event => {
33-
return event.transaction === 'GET /test-local-variables-caught';
34-
});
35-
36-
await fetch(`${baseURL}/test-local-variables-caught`);
37-
38-
const errorEvent = await errorEventPromise;
39-
40-
const frames = errorEvent.exception?.values?.[0]?.stacktrace?.frames;
41-
expect(frames?.[frames.length - 1]?.vars?.randomVariableToRecord).toBeDefined();
42-
});

dev-packages/e2e-tests/test-applications/tsx-express/tests/logs.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { expect, test } from '@playwright/test';
22
import { waitForEnvelopeItem } from '@sentry-internal/test-utils';
3-
import type { SerializedLog, SerializedLogContainer } from '@sentry/core';
3+
import type { SerializedLogContainer } from '@sentry/core';
44

5-
test('should send logs', async ({ baseURL }) => {
5+
test('Sends logs', async ({ baseURL }) => {
66
const logEnvelopePromise = waitForEnvelopeItem('tsx-express', envelope => {
77
return envelope[0].type === 'log' && (envelope[1] as SerializedLogContainer).items[0]?.level === 'debug';
88
});

dev-packages/e2e-tests/test-applications/tsx-express/tests/mcp.test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { waitForTransaction } from '@sentry-internal/test-utils';
33
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
44
import { SSEClientTransport } from '@modelcontextprotocol/sdk/client/sse.js';
55

6-
test('Should record transactions for mcp handlers', async ({ baseURL }) => {
6+
test('Records transactions for mcp handlers', async ({ baseURL }) => {
77
const transport = new SSEClientTransport(new URL(`${baseURL}/sse`));
88

99
const client = new Client({
@@ -18,7 +18,7 @@ test('Should record transactions for mcp handlers', async ({ baseURL }) => {
1818
return transactionEvent.transaction === 'POST /messages';
1919
});
2020
const toolTransactionPromise = waitForTransaction('tsx-express', transactionEvent => {
21-
return transactionEvent.transaction === 'mcp-server/tool:echo';
21+
return transactionEvent.transaction === 'tools/call echo';
2222
});
2323

2424
const toolResult = await client.callTool({
@@ -39,9 +39,12 @@ test('Should record transactions for mcp handlers', async ({ baseURL }) => {
3939

4040
const postTransaction = await postTransactionPromise;
4141
expect(postTransaction).toBeDefined();
42+
expect(postTransaction.contexts?.trace?.op).toEqual('http.server');
4243

4344
const toolTransaction = await toolTransactionPromise;
4445
expect(toolTransaction).toBeDefined();
46+
expect(toolTransaction.contexts?.trace?.op).toEqual('mcp.server');
47+
expect(toolTransaction.contexts?.trace?.data?.['mcp.method.name']).toEqual('tools/call');
4548

4649
// TODO: When https://github.com/modelcontextprotocol/typescript-sdk/pull/358 is released check for trace id equality between the post transaction and the handler transaction
4750
});
@@ -51,7 +54,7 @@ test('Should record transactions for mcp handlers', async ({ baseURL }) => {
5154
return transactionEvent.transaction === 'POST /messages';
5255
});
5356
const resourceTransactionPromise = waitForTransaction('tsx-express', transactionEvent => {
54-
return transactionEvent.transaction === 'mcp-server/resource:echo';
57+
return transactionEvent.transaction === 'resources/read echo://foobar';
5558
});
5659

5760
const resourceResult = await client.readResource({
@@ -76,7 +79,7 @@ test('Should record transactions for mcp handlers', async ({ baseURL }) => {
7679
return transactionEvent.transaction === 'POST /messages';
7780
});
7881
const promptTransactionPromise = waitForTransaction('tsx-express', transactionEvent => {
79-
return transactionEvent.transaction === 'mcp-server/prompt:echo';
82+
return transactionEvent.transaction === 'prompts/get echo';
8083
});
8184

8285
const promptResult = await client.getPrompt({

dev-packages/e2e-tests/test-applications/tsx-express/tests/transactions.test.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ test('Sends an API route transaction', async ({ baseURL }) => {
6666
data: {
6767
'sentry.origin': 'auto.http.otel.express',
6868
'sentry.op': 'middleware.express',
69-
'http.route': '/',
7069
'express.name': 'query',
7170
'express.type': 'middleware',
7271
},
@@ -85,7 +84,6 @@ test('Sends an API route transaction', async ({ baseURL }) => {
8584
data: {
8685
'sentry.origin': 'auto.http.otel.express',
8786
'sentry.op': 'middleware.express',
88-
'http.route': '/',
8987
'express.name': 'expressInit',
9088
'express.type': 'middleware',
9189
},
@@ -144,7 +142,6 @@ test('Sends an API route transaction for an errored route', async ({ baseURL })
144142
data: {
145143
'sentry.origin': 'auto.http.otel.express',
146144
'sentry.op': 'middleware.express',
147-
'http.route': '/',
148145
'express.name': 'query',
149146
'express.type': 'middleware',
150147
},
@@ -163,7 +160,6 @@ test('Sends an API route transaction for an errored route', async ({ baseURL })
163160
data: {
164161
'sentry.origin': 'auto.http.otel.express',
165162
'sentry.op': 'middleware.express',
166-
'http.route': '/',
167163
'express.name': 'expressInit',
168164
'express.type': 'middleware',
169165
},
@@ -192,7 +188,8 @@ test('Sends an API route transaction for an errored route', async ({ baseURL })
192188
parent_span_id: expect.stringMatching(/[a-f0-9]{16}/),
193189
span_id: expect.stringMatching(/[a-f0-9]{16}/),
194190
start_timestamp: expect.any(Number),
195-
status: 'ok',
191+
status: 'unknown_error',
192+
measurements: {},
196193
timestamp: expect.any(Number),
197194
trace_id: expect.stringMatching(/[a-f0-9]{32}/),
198195
});

dev-packages/e2e-tests/test-applications/tsx-express/tests/trpc.test.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { waitForError, waitForTransaction } from '@sentry-internal/test-utils';
33
import { createTRPCProxyClient, httpBatchLink } from '@trpc/client';
44
import type { AppRouter } from '../src/app';
55

6-
test('Should record span for trpc query', async ({ baseURL }) => {
6+
test('Records span for trpc query', async ({ baseURL }) => {
77
const transactionEventPromise = waitForTransaction('tsx-express', transactionEvent => {
88
return (
99
transactionEvent.transaction === 'GET /trpc' &&
@@ -35,7 +35,7 @@ test('Should record span for trpc query', async ({ baseURL }) => {
3535
);
3636
});
3737

38-
test('Should record transaction for trpc mutation', async ({ baseURL }) => {
38+
test('Records transaction for trpc mutation', async ({ baseURL }) => {
3939
const transactionEventPromise = waitForTransaction('tsx-express', transactionEvent => {
4040
return (
4141
transactionEvent.transaction === 'POST /trpc' &&
@@ -67,7 +67,7 @@ test('Should record transaction for trpc mutation', async ({ baseURL }) => {
6767
);
6868
});
6969

70-
test('Should record transaction and error for a crashing trpc handler', async ({ baseURL }) => {
70+
test('Records transaction and error for a crashing trpc handler', async ({ baseURL }) => {
7171
const transactionEventPromise = waitForTransaction('tsx-express', transactionEvent => {
7272
return (
7373
transactionEvent.transaction === 'POST /trpc' &&
@@ -105,16 +105,16 @@ test('Should record transaction and error for a crashing trpc handler', async ({
105105
});
106106
});
107107

108-
test('Should record transaction and error for a trpc handler that returns a status code', async ({ baseURL }) => {
108+
test('Records transaction and error for a trpc handler that returns a status code', async ({ baseURL }) => {
109109
const transactionEventPromise = waitForTransaction('tsx-express', transactionEvent => {
110110
return (
111111
transactionEvent.transaction === 'POST /trpc' &&
112-
!!transactionEvent.spans?.find(span => span.description === 'trpc/unauthorized')
112+
!!transactionEvent.spans?.find(span => span.description === 'trpc/badRequest')
113113
);
114114
});
115115

116116
const errorEventPromise = waitForError('tsx-express', errorEvent => {
117-
return !!errorEvent?.exception?.values?.some(exception => exception.value?.includes('Unauthorized'));
117+
return !!errorEvent?.exception?.values?.some(exception => exception.value?.includes('Bad Request'));
118118
});
119119

120120
const trpcClient = createTRPCProxyClient<AppRouter>({
@@ -125,7 +125,7 @@ test('Should record transaction and error for a trpc handler that returns a stat
125125
],
126126
});
127127

128-
await expect(trpcClient.unauthorized.mutate()).rejects.toBeDefined();
128+
await expect(trpcClient.badRequest.mutate()).rejects.toBeDefined();
129129

130130
await expect(transactionEventPromise).resolves.toBeDefined();
131131
await expect(errorEventPromise).resolves.toBeDefined();

0 commit comments

Comments
 (0)