@@ -94,31 +94,32 @@ export function appRouterInstrumentNavigation(client: Client): void {
94
94
// @ts -expect-error Weird type error related to not knowing how to associate return values with the individual functions - we can just ignore
95
95
router [ routerFunctionName ] = new Proxy ( router [ routerFunctionName ] , {
96
96
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
+ } ;
107
103
108
104
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' ;
112
108
} 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' ;
116
112
} else if ( routerFunctionName === 'back' ) {
117
- span ?. setAttribute ( 'navigation.type' , 'router.back' ) ;
113
+ transactionAttributes [ 'navigation.type' ] = 'router.back' ;
118
114
} else if ( routerFunctionName === 'forward' ) {
119
- span ?. setAttribute ( 'navigation.type' , 'router.forward' ) ;
115
+ transactionAttributes [ 'navigation.type' ] = 'router.forward' ;
120
116
}
121
117
118
+ currentNavigationSpan = startBrowserTracingNavigationSpan ( client , {
119
+ name : transactionName ,
120
+ attributes : transactionAttributes ,
121
+ } ) ;
122
+
122
123
return target . apply ( thisArg , argArray ) ;
123
124
} ,
124
125
} ) ;
0 commit comments