Skip to content

Commit ff8e780

Browse files
authored
test(nextjs): Test for client trace propagation with Turbopack (#14059)
Resolves #13656
1 parent e0820cf commit ff8e780

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
/// <reference types="next" />
22
/// <reference types="next/image-types/global" />
3+
/// <reference types="next/navigation-types/compat/navigation" />
34

45
// NOTE: This file should not be edited
56
// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export default function Page() {
2+
<p>Hello World!</p>;
3+
}
4+
5+
// getServerSideProps makes this page dynamic and allows tracing data to be inserted
6+
export async function getServerSideProps() {
7+
return {
8+
props: {},
9+
};
10+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { expect, test } from '@playwright/test';
2+
import { waitForTransaction } from '@sentry-internal/test-utils';
3+
import { extractTraceparentData } from '@sentry/utils';
4+
5+
test('Should propagate traces from server to client in pages router', async ({ page }) => {
6+
const serverTransactionPromise = waitForTransaction('nextjs-turbo', async transactionEvent => {
7+
return transactionEvent?.transaction === 'GET /[param]/client-trace-propagation';
8+
});
9+
10+
await page.goto(`/123/client-trace-propagation`);
11+
12+
const sentryTraceLocator = await page.locator('meta[name="sentry-trace"]');
13+
const sentryTraceValue = await sentryTraceLocator.getAttribute('content');
14+
expect(sentryTraceValue).toMatch(/^[a-f0-9]{32}-[a-f0-9]{16}-[0-1]$/);
15+
16+
const baggageLocator = await page.locator('meta[name="baggage"]');
17+
const baggageValue = await baggageLocator.getAttribute('content');
18+
expect(baggageValue).toMatch(/sentry-public_key=/);
19+
20+
const traceparentData = extractTraceparentData(sentryTraceValue!);
21+
22+
const serverTransaction = await serverTransactionPromise;
23+
24+
expect(serverTransaction.contexts?.trace?.trace_id).toBe(traceparentData?.traceId);
25+
});

0 commit comments

Comments
 (0)