Skip to content

Commit 963cc3f

Browse files
committed
test(nuxt): Add test for distributed server request
1 parent 2edf0af commit 963cc3f

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

dev-packages/e2e-tests/test-applications/nuxt-4/tests/tracing.test.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,70 @@ test.describe('distributed tracing', () => {
6666
expect(clientTxnEvent.contexts?.trace?.parent_span_id).toBe(serverTxnEvent.contexts?.trace?.span_id);
6767
expect(serverTxnEvent.contexts?.trace?.trace_id).toBe(metaTraceId);
6868
});
69+
70+
test('capture a distributed server request with parametrization', async ({ page }) => {
71+
const clientTxnEventPromise = waitForTransaction('nuxt-4', txnEvent => {
72+
return txnEvent.transaction === '/test-param/:param()';
73+
});
74+
75+
const ssrTxnEventPromise = waitForTransaction('nuxt-4', txnEvent => {
76+
return txnEvent.transaction.includes('GET /test-param/');
77+
});
78+
79+
const serverReqTxnEventPromise = waitForTransaction('nuxt-4', txnEvent => {
80+
return txnEvent.transaction.includes('GET /api/test-param/');
81+
});
82+
83+
const [, clientTxnEvent, ssrTxnEvent, , , serverReqTxnEvent] = await Promise.all([
84+
page.goto(`/test-param/${PARAM}`),
85+
clientTxnEventPromise,
86+
ssrTxnEventPromise,
87+
expect(page.getByText(`Param: ${PARAM}`)).toBeVisible(),
88+
page.getByText('Fetch Server Data', { exact: true }).click(),
89+
serverReqTxnEventPromise,
90+
]);
91+
92+
const httpClientSpan = clientTxnEvent?.spans?.find(span => span.description === `GET /api/test-param/${PARAM}`);
93+
94+
expect(ssrTxnEvent).toMatchObject({
95+
transaction: `GET /test-param/${PARAM}`, // todo: parametrize (nitro)
96+
transaction_info: { source: 'url' },
97+
type: 'transaction',
98+
contexts: {
99+
trace: {
100+
op: 'http.server',
101+
origin: 'auto.http.otel.http',
102+
},
103+
},
104+
});
105+
106+
expect(httpClientSpan).toMatchObject({
107+
description: `GET /api/test-param/${PARAM}`, // todo: parametrize (nitro)
108+
parent_span_id: clientTxnEvent.contexts?.trace?.span_id, // pageload span is parent
109+
data: expect.objectContaining({
110+
'sentry.op': 'http.client',
111+
'sentry.origin': 'auto.http.browser',
112+
'http.request_method': 'GET',
113+
}),
114+
});
115+
116+
expect(serverReqTxnEvent).toMatchObject({
117+
transaction: `GET /api/test-param/${PARAM}`, // todo: parametrize (nitro)
118+
transaction_info: { source: 'url' },
119+
type: 'transaction',
120+
contexts: {
121+
trace: {
122+
op: 'http.server',
123+
origin: 'auto.http.otel.http',
124+
parent_span_id: httpClientSpan?.span_id, // http.client span is parent
125+
},
126+
},
127+
});
128+
129+
// All share the same trace_id
130+
expect(clientTxnEvent.contexts?.trace?.trace_id).toBeDefined();
131+
expect(clientTxnEvent.contexts?.trace?.trace_id).toBe(httpClientSpan?.trace_id);
132+
expect(clientTxnEvent.contexts?.trace?.trace_id).toBe(ssrTxnEvent.contexts?.trace?.trace_id);
133+
expect(clientTxnEvent.contexts?.trace?.trace_id).toBe(serverReqTxnEvent.contexts?.trace?.trace_id);
134+
});
69135
});

0 commit comments

Comments
 (0)