Skip to content

Commit 18d5a48

Browse files
committed
FIX ME NOW??!
1 parent 4b24639 commit 18d5a48

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

packages/nextjs/src/common/wrapRouteHandlerWithSentry.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
startSpan,
1414
withIsolationScope,
1515
} from '@sentry/core';
16+
import { getSpanScopes } from '@sentry/opentelemetry';
1617
import type { Span } from '@sentry/types';
1718
import { winterCGHeadersToDict } from '@sentry/utils';
1819
import { isNotFoundNavigationError, isRedirectNavigationError } from './nextNavigationErrorUtils';
@@ -69,7 +70,6 @@ export function wrapRouteHandlerWithSentry<F extends (...args: any[]) => any>(
6970
return new Proxy(routeHandler, {
7071
apply: (originalFunction, thisArg, args) => {
7172
return withIsolationScope(async isolationScope => {
72-
console.log('SETTING ISOLATION SCOPE');
7373
isolationScope.setSDKProcessingMetadata({
7474
request: {
7575
headers: headers ? winterCGHeadersToDict(headers) : undefined,
@@ -78,6 +78,12 @@ export function wrapRouteHandlerWithSentry<F extends (...args: any[]) => any>(
7878

7979
try {
8080
return await startOrUpdateSpan(`${method} ${parameterizedRoute}`, async (rootSpan: Span) => {
81+
// Ensure root span has the correct isolation scope - even if it was triggered by next
82+
const scopes = getSpanScopes(rootSpan);
83+
if (scopes) {
84+
scopes.isolationScope = isolationScope;
85+
}
86+
8187
const response: Response = await handleCallbackErrors(
8288
() => originalFunction.apply(thisArg, args),
8389
error => {

0 commit comments

Comments
 (0)