Skip to content

Commit f6c87eb

Browse files
committed
Capture span end timestamp immediately to avoid lazy route delay
1 parent 4fdf8d0 commit f6c87eb

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

packages/react/src/reactrouter-compat-utils/instrumentation.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,6 +1037,10 @@ function patchSpanEnd(
10371037
}
10381038
endCalled = true;
10391039

1040+
// Capture timestamp immediately to avoid delay from async operations
1041+
// If no timestamp was provided, capture the current time now
1042+
const endTimestamp = args.length > 0 ? args[0] : Date.now() / 1000;
1043+
10401044
const spanJson = spanToJSON(span);
10411045
const currentName = spanJson.description;
10421046
const currentSource = spanJson.data?.[SEMANTIC_ATTRIBUTE_SENTRY_SOURCE];
@@ -1066,7 +1070,7 @@ function patchSpanEnd(
10661070
if (shouldWaitForLazyRoutes) {
10671071
if (_lazyRouteTimeout === 0) {
10681072
tryUpdateSpanNameBeforeEnd(span, spanJson, currentName, location, routes, basename, spanType, allRoutesSet);
1069-
originalEnd(...args);
1073+
originalEnd(endTimestamp);
10701074
cleanupNavigationSpan();
10711075
return;
10721076
}
@@ -1090,18 +1094,18 @@ function patchSpanEnd(
10901094
spanType,
10911095
allRoutesSet,
10921096
);
1093-
originalEnd(...args);
1097+
originalEnd(endTimestamp);
10941098
cleanupNavigationSpan();
10951099
})
10961100
.catch(() => {
1097-
originalEnd(...args);
1101+
originalEnd(endTimestamp);
10981102
cleanupNavigationSpan();
10991103
});
11001104
return;
11011105
}
11021106

11031107
tryUpdateSpanNameBeforeEnd(span, spanJson, currentName, location, routes, basename, spanType, allRoutesSet);
1104-
originalEnd(...args);
1108+
originalEnd(endTimestamp);
11051109
cleanupNavigationSpan();
11061110
};
11071111

0 commit comments

Comments
 (0)