Skip to content

Commit

Permalink
test(nextjs): Test pages router API routes incoming trace propagation
Browse files Browse the repository at this point in the history
  • Loading branch information
lforst committed Dec 20, 2024
1 parent cd14035 commit 6350286
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { NextApiRequest, NextApiResponse } from 'next';

type Data = {
name: string;
};

export default function handler(req: NextApiRequest, res: NextApiResponse<Data>) {
res.status(200).json({ name: 'John Doe' });
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { expect, test } from '@playwright/test';
import { waitForTransaction } from '@sentry-internal/test-utils';

test('Should create a transaction that has the same trace ID as the incoming request', async ({ request }) => {
const transactionPromise = waitForTransaction('nextjs-app-dir', async transactionEvent => {
return transactionEvent?.transaction === 'GET /api/trace-propagation';
});

await request.get('/api/trace-propagation', {
headers: {
'sentry-trace': '8ef4a40df2063cb023c93cbeb04d68c3-acf68e4724b58822-1',
},
});

expect((await transactionPromise).contexts?.trace).toBe(
expect.objectContaining({
trace_id: '8ef4a40df2063cb023c93cbeb04d68c3',
parent_span_id: 'acf68e4724b58822',
}),
);
});

0 comments on commit 6350286

Please sign in to comment.