Skip to content

Commit 6408cff

Browse files
author
Luca Forstner
committed
fix(nextjs): Don't drop transactions for server components on navigations
1 parent 88656c2 commit 6408cff

File tree

3 files changed

+26
-14
lines changed

3 files changed

+26
-14
lines changed

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

Lines changed: 24 additions & 8 deletions
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/client-app-routing-instrumentation.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ test('Creates a navigation transaction for app router routes', async ({ page })
3838
});
3939

4040
const serverComponentTransactionPromise = waitForTransaction('nextjs-app-dir', async transactionEvent => {
41+
console.log('t', transactionEvent.transaction, transactionEvent.contexts?.trace);
4142
return (
4243
// It seems to differ between Next.js versions whether the route is parameterized or not
4344
(transactionEvent?.transaction === 'GET /server-component/parameter/foo/bar/baz' ||

packages/nextjs/src/server/index.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ export function init(options: NodeOptions): NodeClient | undefined {
238238

239239
// Filter transactions that we explicitly want to drop.
240240
if (event.contexts?.trace?.data?.[TRANSACTION_ATTR_SHOULD_DROP_TRANSACTION]) {
241+
console.log('Dropping transaction:', event.transaction, event.contexts.trace);
241242
return null;
242243
}
243244

@@ -307,12 +308,6 @@ export function init(options: NodeOptions): NodeClient | undefined {
307308
if (typeof method === 'string' && typeof route === 'string') {
308309
event.transaction = `${method} ${route.replace(/\/route$/, '')}`;
309310
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;
316311
}
317312
}
318313

0 commit comments

Comments
 (0)