Skip to content

Commit 48c9f19

Browse files
committed
Add e2e tests for trace continuation and trace isolation
Add test verifying incoming sentry-trace and baggage headers are correctly continued via continueTrace in light mode. Also add trace ID isolation assertions to the concurrent error test.
1 parent 9743db0 commit 48c9f19

2 files changed

Lines changed: 42 additions & 0 deletions

File tree

dev-packages/e2e-tests/test-applications/node-core-light-express/src/app.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ app.get('/test-isolation-error/:userId', (req, res) => {
6969
res.json({ userId, captured: true });
7070
});
7171

72+
app.get('/test-trace-continuation', (_req, res) => {
73+
Sentry.captureException(new Error('Trace continuation error'));
74+
res.json({ ok: true });
75+
});
76+
7277
app.get('/health', (_req, res) => {
7378
res.json({ status: 'ok' });
7479
});

dev-packages/e2e-tests/test-applications/node-core-light-express/tests/request-isolation.test.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import crypto from 'crypto';
12
import { expect, test } from '@playwright/test';
23
import { waitForError } from '@sentry-internal/test-utils';
34

@@ -64,4 +65,40 @@ test('should isolate errors across concurrent requests', async ({ request }) =>
6465

6566
expect(error3?.user?.id).toBe('user-3');
6667
expect(error3?.tags?.user_id).toBe('user-3');
68+
69+
// Each error should have a trace context with a trace_id
70+
const traceId1 = error1?.contexts?.trace?.trace_id;
71+
const traceId2 = error2?.contexts?.trace?.trace_id;
72+
const traceId3 = error3?.contexts?.trace?.trace_id;
73+
74+
expect(traceId1).toBeDefined();
75+
expect(traceId2).toBeDefined();
76+
expect(traceId3).toBeDefined();
77+
78+
// Trace IDs from different requests should be different (isolation)
79+
expect(traceId1).not.toBe(traceId2);
80+
expect(traceId1).not.toBe(traceId3);
81+
expect(traceId2).not.toBe(traceId3);
82+
});
83+
84+
test('should continue trace from incoming sentry-trace and baggage headers', async ({ request }) => {
85+
const traceId = crypto.randomUUID().replace(/-/g, '');
86+
const parentSpanId = traceId.substring(0, 16);
87+
88+
const errorPromise = waitForError('node-core-light-express', event => {
89+
return event?.exception?.values?.[0]?.value === 'Trace continuation error';
90+
});
91+
92+
await request.get('/test-trace-continuation', {
93+
headers: {
94+
'sentry-trace': `${traceId}-${parentSpanId}-1`,
95+
baggage: `sentry-trace_id=${traceId},sentry-environment=test,sentry-public_key=public`,
96+
},
97+
});
98+
99+
const error = await errorPromise;
100+
101+
// The error should inherit the trace ID from the incoming sentry-trace header
102+
expect(error?.contexts?.trace?.trace_id).toBe(traceId);
103+
expect(error?.contexts?.trace?.parent_span_id).toBe(parentSpanId);
67104
});

0 commit comments

Comments
 (0)