@@ -706,15 +706,22 @@ export function handleNavigation(opts: {
706706 basename ,
707707 ) ;
708708
709- const activeSpan = getActiveSpan ( ) ;
710- const spanJson = activeSpan && spanToJSON ( activeSpan ) ;
711- const isAlreadyInNavigationSpan = spanJson ?. op === 'navigation' ;
712- const isSpanForSameRoute = isAlreadyInNavigationSpan && spanJson ?. description === name ;
713-
714709 const currentNavigationKey = getNavigationKey ( location ) ;
715710 const isNavDuplicate = isDuplicateNavigation ( client , currentNavigationKey ) ;
716711
717- if ( ! isSpanForSameRoute && ! isNavDuplicate ) {
712+ if ( isNavDuplicate ) {
713+ // Cross-usage duplicate - update existing span name if better
714+ const activeSpan = getActiveSpan ( ) ;
715+ const spanJson = activeSpan && spanToJSON ( activeSpan ) ;
716+ const isAlreadyInNavigationSpan = spanJson ?. op === 'navigation' ;
717+
718+ if ( isAlreadyInNavigationSpan && activeSpan ) {
719+ tryUpdateSpanName ( activeSpan , spanJson ?. description , name , source ) ;
720+ }
721+ } else {
722+ // Not a cross-usage duplicate - create new span
723+ // This handles: different routes, same route with different params (/user/2 → /user/3)
724+ // startBrowserTracingNavigationSpan will end any active navigation span
718725 createNavigationSpan ( {
719726 client,
720727 name,
@@ -726,8 +733,6 @@ export function handleNavigation(opts: {
726733 allRoutes,
727734 navigationKey : currentNavigationKey ,
728735 } ) ;
729- } else if ( isNavDuplicate && isAlreadyInNavigationSpan && activeSpan ) {
730- tryUpdateSpanName ( activeSpan , spanJson ?. description , name , source ) ;
731736 }
732737 }
733738}
0 commit comments