Skip to content

Commit 18fe54d

Browse files
author
Luca Forstner
committed
test
1 parent 8e75acf commit 18fe54d

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

dev-packages/e2e-tests/test-applications/nextjs-app-dir/tests/client-app-routing-instrumentation.test.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,13 @@ 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 });
41+
console.log({
42+
t: transactionEvent.transaction,
43+
tid: transactionEvent.contexts?.trace?.trace_id,
44+
ctid: (await clientNavigationTransactionPromise).contexts?.trace?.trace_id,
45+
});
4246
return (
43-
// Next.js 14+
44-
(transactionEvent?.transaction === 'GET /server-component/parameter/foo/bar/baz' ||
45-
// Next.js 13
46-
transactionEvent?.transaction === 'GET /server-component/parameter/[...parameters]') &&
47+
transactionEvent?.transaction === 'GET /server-component/parameter/foo/bar/baz' &&
4748
(await clientNavigationTransactionPromise).contexts?.trace?.trace_id ===
4849
transactionEvent.contexts?.trace?.trace_id
4950
);

packages/nextjs/src/common/wrapGenerationFunctionWithSentry.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
Scope,
66
captureException,
77
getActiveSpan,
8+
getCapturedScopesOnSpan,
89
getClient,
910
getRootSpan,
1011
handleCallbackErrors,
@@ -45,8 +46,11 @@ export function wrapGenerationFunctionWithSentry<F extends (...args: any[]) => a
4546
const activeSpan = getActiveSpan();
4647
if (activeSpan) {
4748
const rootSpan = getRootSpan(activeSpan);
49+
const { scope } = getCapturedScopesOnSpan(rootSpan);
50+
setCapturedScopesOnSpan(rootSpan, scope ?? new Scope(), isolationScope);
51+
52+
// We mark the root span as an app router span so we can allow-list it in our span processor that would normally filter out all Next.js transactions/spans
4853
rootSpan.setAttribute('sentry.rsc', true);
49-
setCapturedScopesOnSpan(rootSpan, new Scope(), isolationScope);
5054
}
5155

5256
let data: Record<string, unknown> | undefined = undefined;

packages/nextjs/src/common/wrapServerComponentWithSentry.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
Scope,
66
captureException,
77
getActiveSpan,
8+
getCapturedScopesOnSpan,
89
getRootSpan,
910
handleCallbackErrors,
1011
setCapturedScopesOnSpan,
@@ -40,8 +41,11 @@ export function wrapServerComponentWithSentry<F extends (...args: any[]) => any>
4041
const activeSpan = getActiveSpan();
4142
if (activeSpan) {
4243
const rootSpan = getRootSpan(activeSpan);
44+
const { scope } = getCapturedScopesOnSpan(rootSpan);
45+
setCapturedScopesOnSpan(rootSpan, scope ?? new Scope(), isolationScope);
46+
47+
// We mark the root span as an app router span so we can allow-list it in our span processor that would normally filter out all Next.js transactions/spans
4348
rootSpan.setAttribute('sentry.rsc', true);
44-
setCapturedScopesOnSpan(rootSpan, new Scope(), isolationScope);
4549
}
4650

4751
const headersDict = context.headers ? winterCGHeadersToDict(context.headers) : undefined;

0 commit comments

Comments
 (0)