Skip to content

Commit 8fb46db

Browse files
author
Luca Forstner
committed
Update route handler logic
1 parent ed15166 commit 8fb46db

File tree

2 files changed

+12
-23
lines changed

2 files changed

+12
-23
lines changed

packages/nextjs/src/common/wrapRouteHandlerWithSentry.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ export function wrapRouteHandlerWithSentry<F extends (...args: any[]) => any>(
5151
const activeSpan = getActiveSpan();
5252
if (activeSpan) {
5353
const rootSpan = getRootSpan(activeSpan);
54-
rootSpan.setAttribute('sentry.route_handler', true);
5554
const { scope } = getCapturedScopesOnSpan(rootSpan);
5655
setCapturedScopesOnSpan(rootSpan, scope ?? new Scope(), isolationScope);
5756
}

packages/nextjs/src/server/index.ts

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import {
22
SEMANTIC_ATTRIBUTE_SENTRY_OP,
33
SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN,
4+
SEMANTIC_ATTRIBUTE_SENTRY_SOURCE,
45
applySdkMetadata,
56
getClient,
67
getGlobalScope,
@@ -284,32 +285,21 @@ export function init(options: NodeOptions): NodeClient | undefined {
284285
getGlobalScope().addEventProcessor(
285286
Object.assign(
286287
(event => {
287-
// Sometimes, the HTTP integration will not work, causing us not to properly set an op for spans generated by
288-
// Next.js that are actually more or less correct server HTTP spans, so we are backfilling the op here.
289-
290-
// if (
291-
// event.type === 'transaction' &&
292-
// event.transaction?.match(/^(RSC )?GET /) &&
293-
// event.contexts?.trace?.data?.['sentry.rsc'] === true &&
294-
// !event.contexts.trace.op
295-
// ) {
296-
// event.contexts.trace.data = event.contexts.trace.data || {};
297-
// event.contexts.trace.data[SEMANTIC_ATTRIBUTE_SENTRY_OP] = 'http.server';
298-
// event.contexts.trace.op = 'http.server';
299-
// }
300-
301-
// TODO: Add logic here to backfill things like, parameterized transaction name, op, request interface, etc.
302-
303288
// Enhance route handler transactions
304-
if (event.type === 'transaction' && event.contexts?.trace?.data?.['sentry.route_handler'] === true) {
289+
if (
290+
event.type === 'transaction' &&
291+
event.contexts?.trace?.data?.['next.span_type'] === 'BaseServer.handleRequest'
292+
) {
305293
event.contexts.trace.data = event.contexts.trace.data || {};
306294
event.contexts.trace.data[SEMANTIC_ATTRIBUTE_SENTRY_OP] = 'http.server';
307295
event.contexts.trace.op = 'http.server';
308-
if (typeof event.contexts.trace.data[ATTR_HTTP_ROUTE] === 'string') {
309-
// eslint-disable-next-line deprecation/deprecation
310-
event.transaction = `${event.contexts.trace.data[SEMATTRS_HTTP_METHOD]} ${event.contexts.trace.data[
311-
ATTR_HTTP_ROUTE
312-
].replace(/\/route$/, '')}`;
296+
297+
// eslint-disable-next-line deprecation/deprecation
298+
const method = event.contexts.trace.data[SEMATTRS_HTTP_METHOD];
299+
const route = event.contexts.trace.data[ATTR_HTTP_ROUTE];
300+
if (typeof method === 'string' && typeof route === 'string') {
301+
event.transaction = `${method} ${route.replace(/\/route$/, '')}`;
302+
event.contexts.trace.data[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE] = 'route';
313303
}
314304
}
315305

0 commit comments

Comments
 (0)