@@ -830,14 +830,21 @@ export function handleNavigation(opts: {
830830 } ;
831831 activeNavigationSpans . set ( client , placeholderEntry ) ;
832832
833- const navigationSpan = startBrowserTracingNavigationSpan ( client , {
834- name : placeholderEntry . routeName , // Use placeholder's routeName in case it was updated
835- attributes : {
836- [ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] : source ,
837- [ SEMANTIC_ATTRIBUTE_SENTRY_OP ] : 'navigation' ,
838- [ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : `auto.navigation.react.reactrouter_v${ version } ` ,
839- } ,
840- } ) ;
833+ let navigationSpan : Span | undefined ;
834+ try {
835+ navigationSpan = startBrowserTracingNavigationSpan ( client , {
836+ name : placeholderEntry . routeName , // Use placeholder's routeName in case it was updated
837+ attributes : {
838+ [ SEMANTIC_ATTRIBUTE_SENTRY_SOURCE ] : source ,
839+ [ SEMANTIC_ATTRIBUTE_SENTRY_OP ] : 'navigation' ,
840+ [ SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN ] : `auto.navigation.react.reactrouter_v${ version } ` ,
841+ } ,
842+ } ) ;
843+ } catch ( e ) {
844+ // If span creation fails, remove the placeholder so we don't block future navigations
845+ activeNavigationSpans . delete ( client ) ;
846+ throw e ;
847+ }
841848
842849 if ( navigationSpan ) {
843850 // Update the map with the real span (isPlaceholder omitted, defaults to false)
@@ -1070,8 +1077,8 @@ function patchSpanEnd(
10701077 if ( shouldWaitForLazyRoutes ) {
10711078 if ( _lazyRouteTimeout === 0 ) {
10721079 tryUpdateSpanNameBeforeEnd ( span , spanJson , currentName , location , routes , basename , spanType , allRoutesSet ) ;
1073- originalEnd ( endTimestamp ) ;
10741080 cleanupNavigationSpan ( ) ;
1081+ originalEnd ( endTimestamp ) ;
10751082 return ;
10761083 }
10771084
@@ -1094,19 +1101,19 @@ function patchSpanEnd(
10941101 spanType ,
10951102 allRoutesSet ,
10961103 ) ;
1097- originalEnd ( endTimestamp ) ;
10981104 cleanupNavigationSpan ( ) ;
1105+ originalEnd ( endTimestamp ) ;
10991106 } )
11001107 . catch ( ( ) => {
1101- originalEnd ( endTimestamp ) ;
11021108 cleanupNavigationSpan ( ) ;
1109+ originalEnd ( endTimestamp ) ;
11031110 } ) ;
11041111 return ;
11051112 }
11061113
11071114 tryUpdateSpanNameBeforeEnd ( span , spanJson , currentName , location , routes , basename , spanType , allRoutesSet ) ;
1108- originalEnd ( endTimestamp ) ;
11091115 cleanupNavigationSpan ( ) ;
1116+ originalEnd ( endTimestamp ) ;
11101117 } ;
11111118
11121119 addNonEnumerableProperty ( span as unknown as Record < string , boolean > , patchedPropertyName , true ) ;
0 commit comments