Skip to content

Commit 4823b23

Browse files
author
Luca Forstner
committed
fix(browser): Ensure that performance.measure spans have a positive duration
1 parent a31e0d3 commit 4823b23

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ export function _addMeasureSpans(
425425
startTime: number,
426426
duration: number,
427427
timeOrigin: number,
428-
): number {
428+
): void {
429429
const navEntry = getNavigationEntry(false);
430430
const requestTime = msToSec(navEntry ? navEntry.requestStart : 0);
431431
// Because performance.measure accepts arbitrary timestamps it can produce
@@ -450,13 +450,14 @@ export function _addMeasureSpans(
450450
attributes['sentry.browser.measure_start_time'] = measureStartTimestamp;
451451
}
452452

453-
startAndEndSpan(span, measureStartTimestamp, measureEndTimestamp, {
454-
name: entry.name as string,
455-
op: entry.entryType as string,
456-
attributes,
457-
});
458-
459-
return measureStartTimestamp;
453+
// Measurements from third parties can be off, which would create invalid spans, dropping transactions in the process.
454+
if (measureStartTimestamp <= measureEndTimestamp) {
455+
startAndEndSpan(span, measureStartTimestamp, measureEndTimestamp, {
456+
name: entry.name as string,
457+
op: entry.entryType as string,
458+
attributes,
459+
});
460+
}
460461
}
461462

462463
/** Instrument navigation entries */

0 commit comments

Comments
 (0)