Skip to content

Commit 02a709f

Browse files
authored
fix(nextjs): Prevent wrong culprit from showing up for clientside error events (#15475)
1 parent 4c54bed commit 02a709f

File tree

1 file changed

+19
-18
lines changed

1 file changed

+19
-18
lines changed

packages/nextjs/src/client/routing/appRouterRoutingInstrumentation.ts

+19-18
Original file line numberDiff line numberDiff line change
@@ -94,31 +94,32 @@ export function appRouterInstrumentNavigation(client: Client): void {
9494
// @ts-expect-error Weird type error related to not knowing how to associate return values with the individual functions - we can just ignore
9595
router[routerFunctionName] = new Proxy(router[routerFunctionName], {
9696
apply(target, thisArg, argArray) {
97-
const span = startBrowserTracingNavigationSpan(client, {
98-
name: INCOMPLETE_APP_ROUTER_INSTRUMENTATION_TRANSACTION_NAME,
99-
attributes: {
100-
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'navigation',
101-
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.navigation.nextjs.app_router_instrumentation',
102-
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url',
103-
},
104-
});
105-
106-
currentNavigationSpan = span;
97+
let transactionName = INCOMPLETE_APP_ROUTER_INSTRUMENTATION_TRANSACTION_NAME;
98+
const transactionAttributes: Record<string, string> = {
99+
[SEMANTIC_ATTRIBUTE_SENTRY_OP]: 'navigation',
100+
[SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.navigation.nextjs.app_router_instrumentation',
101+
[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: 'url',
102+
};
107103

108104
if (routerFunctionName === 'push') {
109-
span?.updateName(transactionNameifyRouterArgument(argArray[0]));
110-
span?.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'url');
111-
span?.setAttribute('navigation.type', 'router.push');
105+
transactionName = transactionNameifyRouterArgument(argArray[0]);
106+
transactionAttributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE] = 'url';
107+
transactionAttributes['navigation.type'] = 'router.push';
112108
} else if (routerFunctionName === 'replace') {
113-
span?.updateName(transactionNameifyRouterArgument(argArray[0]));
114-
span?.setAttribute(SEMANTIC_ATTRIBUTE_SENTRY_SOURCE, 'url');
115-
span?.setAttribute('navigation.type', 'router.replace');
109+
transactionName = transactionNameifyRouterArgument(argArray[0]);
110+
transactionAttributes[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE] = 'url';
111+
transactionAttributes['navigation.type'] = 'router.replace';
116112
} else if (routerFunctionName === 'back') {
117-
span?.setAttribute('navigation.type', 'router.back');
113+
transactionAttributes['navigation.type'] = 'router.back';
118114
} else if (routerFunctionName === 'forward') {
119-
span?.setAttribute('navigation.type', 'router.forward');
115+
transactionAttributes['navigation.type'] = 'router.forward';
120116
}
121117

118+
currentNavigationSpan = startBrowserTracingNavigationSpan(client, {
119+
name: transactionName,
120+
attributes: transactionAttributes,
121+
});
122+
122123
return target.apply(thisArg, argArray);
123124
},
124125
});

0 commit comments

Comments
 (0)