-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(nextjs): Test pages router API routes incoming trace propagation
- Loading branch information
Showing
2 changed files
with
30 additions
and
0 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
dev-packages/e2e-tests/test-applications/nextjs-app-dir/pages/api/trace-propagation.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' }); | ||
} |
21 changes: 21 additions & 0 deletions
21
...-tests/test-applications/nextjs-app-dir/tests/pages-api-handler-trace-propagation.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}), | ||
); | ||
}); |