in packages/rum-core/src/performance-monitoring/navigation/capture-navigation.js [38:136]
function captureNavigation(transaction) {
/**
* Do not capture timing related information when the
* flag is set to false, By default both page-load and route-change
* transactions set this flag to true
*/
if (!transaction.captureTimings) {
/**
* Make sure page load transactions always starts at 0 irrespective if we capture navigation metrics or not
* otherwise we would be reporting different page load durations for sampled and unsampled transactions
*/
if (transaction.type === PAGE_LOAD) {
transaction._start = 0
}
return
}
/**
* Both start and end threshold decides if a span must be
* captured as part of the transaction
*/
const trEnd = transaction._end
/**
* Page load is considered as hard navigation and we account
* for few extra spans than soft navigations which
* happens on single page applications
*/
if (transaction.type === PAGE_LOAD) {
/**
* Adjust custom marks properly to fit in the transaction timeframe
*/
if (transaction.marks && transaction.marks.custom) {
const customMarks = transaction.marks.custom
Object.keys(customMarks).forEach(key => {
customMarks[key] += transaction._start
})
}
/**
* must be zero otherwise the calculated relative _start time would be wrong
*/
const trStart = 0
transaction._start = trStart
const timings = PERF.timing
const baseTime = isRedirectInfoAvailable(timings)
? timings.redirectStart // make sure navigation spans will show up after the Redirect span
: timings.fetchStart
createNavigationTimingSpans(timings, baseTime, trStart, trEnd).forEach(
span => {
span.traceId = transaction.traceId
span.sampled = transaction.sampled
if (span.pageResponse && transaction.options.pageLoadSpanId) {
span.id = transaction.options.pageLoadSpanId
}
transaction.spans.push(span)
}
)
/**
* Set the parent id of the transaction to the page load parent ID.
* This means that the backend transaction will be the parent of
* the page load transaction, which is useful for e.g Synthetics.
*/
if (transaction.options.pageLoadParentId) {
transaction.parentId = transaction.options.pageLoadParentId
}
/**
* Page load marks that are gathered from NavigationTiming API
*/
transaction.addMarks(getPageLoadMarks(timings))
}
if (isPerfTimelineSupported()) {
const trStart = transaction._start
/**
* Capture resource timing information as spans
*/
const resourceEntries = PERF.getEntriesByType(RESOURCE)
createResourceTimingSpans(
resourceEntries,
state.bootstrapTime,
trStart,
trEnd
).forEach(span => transaction.spans.push(span))
/**
* Capture user timing measures as spans
*/
const userEntries = PERF.getEntriesByType(MEASURE)
createUserTimingSpans(userEntries, trStart, trEnd).forEach(span =>
transaction.spans.push(span)
)
}
}