@@ -361,14 +361,30 @@ 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 spanJSON = activeSpan
366+ ? spanToJSON ( activeSpan )
367+ : {
368+ description : '' ,
369+ op : '' ,
370+ } ;
371+
372+ const isAlreadyInNavigationSpan = spanJSON && spanJSON . op === 'navigation' ;
373+
374+ // Cross usage can result in multiple navigation spans being created without this check
375+ if ( isAlreadyInNavigationSpan ) {
376+ activeSpan ?. updateName ( name ) ;
377+ activeSpan ?. setAttribute ( SEMANTIC_ATTRIBUTE_SENTRY_SOURCE , source ) ;
378+ } else {
379+ startBrowserTracingNavigationSpan ( client , {
380+ name,
381+ attributes : {
382+ [ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] : source ,
383+ [ SEMANTIC_ATTRIBUTE_SENTRY_OP ] : 'navigation' ,
384+ [ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : `auto.navigation.react.reactrouter_v${ version } ` ,
385+ } ,
386+ } ) ;
387+ }
372388 }
373389}
374390
@@ -450,7 +466,6 @@ function addRoutesToAllRoutes(routes: RouteObject[]): void {
450466 } ) ;
451467}
452468
453-
454469function getChildRoutesRecursively ( route : RouteObject , allRoutes : Set < RouteObject > = new Set ( ) ) : Set < RouteObject > {
455470 if ( ! allRoutes . has ( route ) ) {
456471 allRoutes . add ( route ) ;
0 commit comments