Skip to content

Commit ddcaf0d

Browse files
committed
add e2e test for checking span order
1 parent 0d8c866 commit ddcaf0d

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

dev-packages/e2e-tests/test-applications/nextjs-app-dir/tests/transactions.test.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,34 @@ test('Should send a transaction for instrumented server actions', async ({ page
7676
expect(Object.keys(transactionEvent.request?.headers || {}).length).toBeGreaterThan(0);
7777
});
7878

79+
test('Should send a wrapped server action as a child of a nextjs transaction', async ({ page }) => {
80+
const nextjsVersion = packageJson.dependencies.next;
81+
const nextjsMajor = Number(nextjsVersion.split('.')[0]);
82+
test.skip(!isNaN(nextjsMajor) && nextjsMajor < 14, 'only applies to nextjs apps >= version 14');
83+
test.skip(process.env.TEST_ENV === 'development', 'this magically only works in production');
84+
85+
const nextjsPostTransactionPromise = waitForTransaction('nextjs-app-dir', async transactionEvent => {
86+
return (
87+
transactionEvent?.transaction === 'POST /server-action' && transactionEvent.contexts?.trace?.origin === 'auto'
88+
);
89+
});
90+
91+
const serverActionTransactionPromise = waitForTransaction('nextjs-app-dir', async transactionEvent => {
92+
return transactionEvent?.transaction === 'serverAction/myServerAction';
93+
});
94+
95+
await page.goto('/server-action');
96+
await page.getByText('Run Action').click();
97+
98+
const nextjsTransaction = await nextjsPostTransactionPromise;
99+
const serverActionTransaction = await serverActionTransactionPromise;
100+
101+
expect(nextjsTransaction).toBeDefined();
102+
expect(serverActionTransaction).toBeDefined();
103+
104+
expect(nextjsTransaction.contexts?.trace?.span_id).toBe(serverActionTransaction.contexts?.trace?.parent_span_id);
105+
});
106+
79107
test('Should set not_found status for server actions calling notFound()', async ({ page }) => {
80108
const nextjsVersion = packageJson.dependencies.next;
81109
const nextjsMajor = Number(nextjsVersion.split('.')[0]);

0 commit comments

Comments
 (0)