Skip to content

Commit

Permalink
fix(browser): Fix bug causing unintentional dropping of transactions (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
lforst committed Jul 17, 2024
1 parent 36d1d43 commit e710f3b
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/browser-utils/src/metrics/browserMetrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,13 @@ export function addPerformanceEntries(span: Span): void {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
performanceEntries.slice(_performanceCursor).forEach((entry: Record<string, any>) => {
const startTime = msToSec(entry.startTime);
const duration = msToSec(entry.duration);
const duration = msToSec(
// Inexplicibly, Chrome sometimes emits a negative duration. We need to work around this.
// 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
// 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.
// 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.
Math.max(0, entry.duration),
);

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

0 comments on commit e710f3b

Please sign in to comment.