Skip to content

Commit e710f3b

Browse files
authored
fix(browser): Fix bug causing unintentional dropping of transactions (#12933)
1 parent 36d1d43 commit e710f3b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

packages/browser-utils/src/metrics/browserMetrics.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,13 @@ export function addPerformanceEntries(span: Span): void {
287287
// eslint-disable-next-line @typescript-eslint/no-explicit-any
288288
performanceEntries.slice(_performanceCursor).forEach((entry: Record<string, any>) => {
289289
const startTime = msToSec(entry.startTime);
290-
const duration = msToSec(entry.duration);
290+
const duration = msToSec(
291+
// Inexplicibly, Chrome sometimes emits a negative duration. We need to work around this.
292+
// There is a SO post attempting to explain this, but it leaves one with open questions: https://stackoverflow.com/questions/23191918/peformance-getentries-and-negative-duration-display
293+
// The way we clamp the value is probably not accurate, since we have observed this happen for things that may take a while to load, like for example the replay worker.
294+
// TODO: Investigate why this happens and how to properly mitigate. For now, this is a workaround to prevent transactions being dropped due to negative duration spans.
295+
Math.max(0, entry.duration),
296+
);
291297

292298
if (op === 'navigation' && transactionStartTime && timeOrigin + startTime < transactionStartTime) {
293299
return;

0 commit comments

Comments
 (0)