@@ -361,14 +361,23 @@ export function handleNavigation(opts: {
361361 [ name , source ] = getNormalizedName ( routes , location , branches , basename ) ;
362362 }
363363
364- startBrowserTracingNavigationSpan ( client , {
365- name,
366- attributes : {
367- [ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] : source ,
368- [ SEMANTIC_ATTRIBUTE_SENTRY_OP ] : 'navigation' ,
369- [ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : `auto.navigation.react.reactrouter_v${ version } ` ,
370- } ,
371- } ) ;
364+ const activeSpan = getActiveSpan ( ) ;
365+ const isAlreadyInNavigationSpan = activeSpan && spanToJSON ( activeSpan ) . op === 'navigation' ;
366+
367+ // Cross usage can result in multiple navigation spans being created without this check
368+ if ( isAlreadyInNavigationSpan ) {
369+ activeSpan ?. updateName ( name ) ;
370+ activeSpan ?. setAttribute ( SEMANTIC_ATTRIBUTE_SENTRY_SOURCE , source ) ;
371+ } else {
372+ startBrowserTracingNavigationSpan ( client , {
373+ name,
374+ attributes : {
375+ [ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] : source ,
376+ [ SEMANTIC_ATTRIBUTE_SENTRY_OP ] : 'navigation' ,
377+ [ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : `auto.navigation.react.reactrouter_v${ version } ` ,
378+ } ,
379+ } ) ;
380+ }
372381 }
373382}
374383
@@ -450,7 +459,6 @@ function addRoutesToAllRoutes(routes: RouteObject[]): void {
450459 } ) ;
451460}
452461
453-
454462function getChildRoutesRecursively ( route : RouteObject , allRoutes : Set < RouteObject > = new Set ( ) ) : Set < RouteObject > {
455463 if ( ! allRoutes . has ( route ) ) {
456464 allRoutes . add ( route ) ;
0 commit comments