Skip to content

Commit 2516846

Browse files
committed
fix: set the transaction name on the isolation scope level
1 parent c59e752 commit 2516846

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

packages/nextjs/src/common/pages-router-instrumentation/wrapApiHandlerWithSentry.ts

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
import {
2-
captureException,
3-
debug,
4-
getCurrentScope,
5-
getIsolationScope,
6-
httpRequestToRequestData,
7-
objectify,
8-
} from '@sentry/core';
1+
import { captureException, debug, getIsolationScope, httpRequestToRequestData, objectify } from '@sentry/core';
92
import type { NextApiRequest } from 'next';
103
import type { AugmentedNextApiResponse, NextApiHandler } from '../types';
114
import { flushSafelyWithTimeout } from '../utils/responseEnd';
@@ -50,12 +43,13 @@ export function wrapApiHandlerWithSentry(apiHandler: NextApiHandler, parameteriz
5043

5144
req.__withSentry_applied__ = true;
5245

53-
// Set transaction name even without tracing to ensure parameterized routes are used
46+
// Set transaction name on isolation scope to ensure parameterized routes are used
47+
// The HTTP server integration sets it on isolation scope, so we need to match that
5448
const method = req.method || 'GET';
55-
getCurrentScope().setTransactionName(`${method} ${parameterizedRoute}`);
56-
49+
const isolationScope = getIsolationScope();
50+
isolationScope.setTransactionName(`${method} ${parameterizedRoute}`);
5751
// Set SDK processing metadata
58-
getIsolationScope().setSDKProcessingMetadata({
52+
isolationScope.setSDKProcessingMetadata({
5953
normalizedRequest: httpRequestToRequestData(req),
6054
});
6155

0 commit comments

Comments
 (0)