Skip to content

Commit

Permalink
test(nextjs): Test for client trace propagation with Turbopack (#14059)
Browse files Browse the repository at this point in the history
Resolves #13656
  • Loading branch information
lforst authored Oct 28, 2024
1 parent e0820cf commit ff8e780
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/// <reference types="next" />
/// <reference types="next/image-types/global" />
/// <reference types="next/navigation-types/compat/navigation" />

// NOTE: This file should not be edited
// see https://nextjs.org/docs/app/building-your-application/configuring/typescript for more information.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default function Page() {
<p>Hello World!</p>;
}

// getServerSideProps makes this page dynamic and allows tracing data to be inserted
export async function getServerSideProps() {
return {
props: {},
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { expect, test } from '@playwright/test';
import { waitForTransaction } from '@sentry-internal/test-utils';
import { extractTraceparentData } from '@sentry/utils';

test('Should propagate traces from server to client in pages router', async ({ page }) => {
const serverTransactionPromise = waitForTransaction('nextjs-turbo', async transactionEvent => {
return transactionEvent?.transaction === 'GET /[param]/client-trace-propagation';
});

await page.goto(`/123/client-trace-propagation`);

const sentryTraceLocator = await page.locator('meta[name="sentry-trace"]');
const sentryTraceValue = await sentryTraceLocator.getAttribute('content');
expect(sentryTraceValue).toMatch(/^[a-f0-9]{32}-[a-f0-9]{16}-[0-1]$/);

const baggageLocator = await page.locator('meta[name="baggage"]');
const baggageValue = await baggageLocator.getAttribute('content');
expect(baggageValue).toMatch(/sentry-public_key=/);

const traceparentData = extractTraceparentData(sentryTraceValue!);

const serverTransaction = await serverTransactionPromise;

expect(serverTransaction.contexts?.trace?.trace_id).toBe(traceparentData?.traceId);
});

0 comments on commit ff8e780

Please sign in to comment.