Skip to content

Commit 830e4d4

Browse files
fix: guard against negative stats when non-fired events are 0
1 parent 36b0a90 commit 830e4d4

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

ui/src/cloud/utils/rum.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,22 @@ export const buildFieldsFromTiming = function buildFieldsFromTiming(
3434
const totalServer = timing.responseEnd - timing.requestStart
3535

3636
// UI measurements
37-
const domProcessing = timing.domComplete - timing.responseEnd
38-
const domContentLoading = timing.domComplete - timing.domInteractive
39-
const windowLoadEvent = timing.loadEventEnd - timing.loadEventStart
37+
let domProcessing = timing.responseEnd
38+
let domContentLoading = timing.domInteractive
39+
let windowLoadEvent = timing.loadEventStart
4040

41+
// these values will be 0 if the event hasn't fired (e.g. because it's not finished) before the request is sent
42+
if (timing.domComplete > 0) {
43+
domProcessing = timing.domComplete - timing.responseEnd
44+
}
45+
if (timing.domComplete > 0) {
46+
domContentLoading = timing.domComplete - timing.domInteractive
47+
}
48+
if (windowLoadEvent > 0) {
49+
windowLoadEvent = timing.loadEventEnd - timing.loadEventStart
50+
}
51+
52+
// tls and worker may not be set by the user agent - guard against that
4153
let tls = 0
4254
if (timing.secureConnectionStart > 0) {
4355
tls = timing.connectEnd - timing.secureConnectionStart

0 commit comments

Comments
 (0)