Skip to content

Commit

Permalink
🐛 [RUM-2782] remove buggy redirect timing estimation based on fetchSt…
Browse files Browse the repository at this point in the history
…art (#2683)

* 🐛 [RUM-2782] remove redirect estimation based on fetchStart

* 👌 clarify the condition a bit

* 👌 clearer condition
  • Loading branch information
BenoitZugmeyer authored Apr 4, 2024
1 parent 61258c1 commit c47a9dd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 59 deletions.
20 changes: 1 addition & 19 deletions packages/rum-core/src/domain/resource/resourceUtils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ describe('computePerformanceResourceDetails', () => {
},
{
reason: 'redirectStart > redirectEnd',
redirectEnd: 10 as RelativeTime,
redirectEnd: 15 as RelativeTime,
redirectStart: 20 as RelativeTime,
},
{
Expand Down Expand Up @@ -259,24 +259,6 @@ describe('computePerformanceResourceDetails', () => {
first_byte: { start: 0 as ServerDuration, duration: 30e6 as ServerDuration },
})
})

it('should use startTime and fetchStart as fallback for redirectStart and redirectEnd', () => {
expect(
computePerformanceResourceDetails(
generateResourceWith({
redirectEnd: 0 as RelativeTime,
redirectStart: 0 as RelativeTime,
})
)
).toEqual({
connect: { start: 5e6 as ServerDuration, duration: 2e6 as ServerDuration },
dns: { start: 3e6 as ServerDuration, duration: 1e6 as ServerDuration },
download: { start: 40e6 as ServerDuration, duration: 10e6 as ServerDuration },
first_byte: { start: 10e6 as ServerDuration, duration: 30e6 as ServerDuration },
redirect: { start: 0 as ServerDuration, duration: 2e6 as ServerDuration },
ssl: { start: 6e6 as ServerDuration, duration: 1e6 as ServerDuration },
})
})
})

describe('computePerformanceResourceDuration', () => {
Expand Down
58 changes: 18 additions & 40 deletions packages/rum-core/src/domain/resource/resourceUtils.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import type { RelativeTime, ServerDuration } from '@datadog/browser-core'
import {
assign,
addTelemetryDebug,
elapsed,
getPathName,
Expand Down Expand Up @@ -140,50 +139,29 @@ export function toValidEntry(entry: RumPerformanceResourceTiming) {
// RumPerformanceResourceTiming, it will ignore entries from requests where timings cannot be
// collected, for example cross origin requests without a "Timing-Allow-Origin" header allowing
// it.
if (
!areInOrder(
entry.startTime,
entry.fetchStart,
entry.domainLookupStart,
entry.domainLookupEnd,
entry.connectStart,
entry.connectEnd,
entry.requestStart,
entry.responseStart,
entry.responseEnd
)
) {
return undefined
}

if (!hasRedirection(entry)) {
const areCommonTimingsInOrder = areInOrder(
entry.startTime,
entry.fetchStart,
entry.domainLookupStart,
entry.domainLookupEnd,
entry.connectStart,
entry.connectEnd,
entry.requestStart,
entry.responseStart,
entry.responseEnd
)

const areRedirectionTimingsInOrder = hasRedirection(entry)
? areInOrder(entry.startTime, entry.redirectStart, entry.redirectEnd, entry.fetchStart)
: true

if (areCommonTimingsInOrder && areRedirectionTimingsInOrder) {
return entry
}

let { redirectStart, redirectEnd } = entry
// Firefox doesn't provide redirect timings on cross origin requests.
// Provide a default for those.
if (redirectStart < entry.startTime) {
redirectStart = entry.startTime
}
if (redirectEnd < entry.startTime) {
redirectEnd = entry.fetchStart
}

// Make sure redirect timings are in order
if (!areInOrder(entry.startTime, redirectStart, redirectEnd, entry.fetchStart)) {
return undefined
}

return assign({}, entry, {
redirectEnd,
redirectStart,
})
}

function hasRedirection(entry: RumPerformanceResourceTiming) {
// The only time fetchStart is different than startTime is if a redirection occurred.
return entry.fetchStart !== entry.startTime
return entry.redirectEnd > entry.startTime
}

function formatTiming(origin: RelativeTime, start: RelativeTime, end: RelativeTime) {
Expand Down

0 comments on commit c47a9dd

Please sign in to comment.