Skip to content

Commit e979c75

Browse files
authored
fix(nextjs): Don't drop transactions for server components on navigations (#13980)
We were dropping a few too many transactions.
1 parent 88656c2 commit e979c75

File tree

3 files changed

+27
-16
lines changed

3 files changed

+27
-16
lines changed

dev-packages/e2e-tests/test-applications/nextjs-app-dir/app/layout.tsx

+24-8
Original file line numberDiff line numberDiff line change
@@ -9,33 +9,49 @@ export default function Layout({ children }: { children: React.ReactNode }) {
99
<h1>Layout (/)</h1>
1010
<ul>
1111
<li>
12-
<Link href="/">/</Link>
12+
<Link href="/" prefetch={false}>
13+
/
14+
</Link>
1315
</li>
1416
<li>
15-
<Link href="/client-component">/client-component</Link>
17+
<Link href="/client-component" prefetch={false}>
18+
/client-component
19+
</Link>
1620
</li>
1721
<li>
18-
<Link href="/client-component/parameter/42">/client-component/parameter/42</Link>
22+
<Link href="/client-component/parameter/42" prefetch={false}>
23+
/client-component/parameter/42
24+
</Link>
1925
</li>
2026
<li>
21-
<Link href="/client-component/parameter/foo/bar/baz">/client-component/parameter/foo/bar/baz</Link>
27+
<Link href="/client-component/parameter/foo/bar/baz" prefetch={false}>
28+
/client-component/parameter/foo/bar/baz
29+
</Link>
2230
</li>
2331
<li>
24-
<Link href="/server-component">/server-component</Link>
32+
<Link href="/server-component" prefetch={false}>
33+
/server-component
34+
</Link>
2535
</li>
2636
<li>
27-
<Link href="/server-component/parameter/42">/server-component/parameter/42</Link>
37+
<Link href="/server-component/parameter/42" prefetch={false}>
38+
/server-component/parameter/42
39+
</Link>
2840
</li>
2941
<li>
3042
<Link href="/server-component/parameter/foo/bar/baz" prefetch={false}>
3143
/server-component/parameter/foo/bar/baz
3244
</Link>
3345
</li>
3446
<li>
35-
<Link href="/not-found">/not-found</Link>
47+
<Link href="/not-found" prefetch={false}>
48+
/not-found
49+
</Link>
3650
</li>
3751
<li>
38-
<Link href="/redirect">/redirect</Link>
52+
<Link href="/redirect" prefetch={false}>
53+
/redirect
54+
</Link>
3955
</li>
4056
</ul>
4157
<SpanContextProvider>{children}</SpanContextProvider>

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

+3-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import { waitForError, waitForTransaction } from '@sentry-internal/test-utils';
44
test('Should create a transaction for edge routes', async ({ request }) => {
55
const edgerouteTransactionPromise = waitForTransaction('nextjs-app-dir', async transactionEvent => {
66
return (
7-
transactionEvent?.transaction === 'GET /api/edge-endpoint' && transactionEvent?.contexts?.trace?.status === 'ok'
7+
transactionEvent?.transaction === 'GET /api/edge-endpoint' &&
8+
transactionEvent?.contexts?.trace?.status === 'ok' &&
9+
transactionEvent.contexts?.runtime?.name === 'vercel-edge'
810
);
911
});
1012

@@ -19,7 +21,6 @@ test('Should create a transaction for edge routes', async ({ request }) => {
1921

2022
expect(edgerouteTransaction.contexts?.trace?.status).toBe('ok');
2123
expect(edgerouteTransaction.contexts?.trace?.op).toBe('http.server');
22-
expect(edgerouteTransaction.contexts?.runtime?.name).toBe('vercel-edge');
2324
expect(edgerouteTransaction.request?.headers?.['x-yeet']).toBe('test-value');
2425
});
2526

packages/nextjs/src/server/index.ts

-6
Original file line numberDiff line numberDiff line change
@@ -307,12 +307,6 @@ export function init(options: NodeOptions): NodeClient | undefined {
307307
if (typeof method === 'string' && typeof route === 'string') {
308308
event.transaction = `${method} ${route.replace(/\/route$/, '')}`;
309309
event.contexts.trace.data[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE] = 'route';
310-
} else {
311-
// If we cannot hoist the route (or rather parameterize the transaction) for BaseServer.handleRequest spans,
312-
// we drop it because the chance that it is a low-quality transaction we don't want is pretty high.
313-
// This is important in the case of edge-runtime where Next.js will also create unnecessary Node.js root
314-
// spans, that are not parameterized.
315-
return null;
316310
}
317311
}
318312

0 commit comments

Comments
 (0)