diff --git a/packages/rum-core/src/performance-monitoring/navigation/capture-navigation.js b/packages/rum-core/src/performance-monitoring/navigation/capture-navigation.js index 07e515fc6..8498f61a9 100644 --- a/packages/rum-core/src/performance-monitoring/navigation/capture-navigation.js +++ b/packages/rum-core/src/performance-monitoring/navigation/capture-navigation.js @@ -42,6 +42,12 @@ function captureNavigation(transaction) { * 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 } diff --git a/packages/rum-core/test/performance-monitoring/capture-navigation.spec.js b/packages/rum-core/test/performance-monitoring/capture-navigation.spec.js index 9d07a72f9..fcf21cbb9 100644 --- a/packages/rum-core/test/performance-monitoring/capture-navigation.spec.js +++ b/packages/rum-core/test/performance-monitoring/capture-navigation.spec.js @@ -53,7 +53,7 @@ function mapSpan(s) { describe('Capture hard navigation', function () { /** - * Arbitrary value considering the transcation end would be called + * Arbitrary value considering the transaction end would be called * after load event has finished */ const transactionEnd = timings.loadEventEnd + 100 @@ -398,6 +398,25 @@ describe('Capture hard navigation', function () { expect(tr.marks.custom.testMark).toEqual(start + markValue) }) + // relevant for sampled and unsampled PAGE LOAD transactions: + ;[ + { + value: true, + description: 'enabled' + }, + { + value: false, + description: 'disabled' + } + ].forEach(({ value, description }) => { + it(`should set transaction._start to 0 for PAGE_LOAD when captureTimings flag is ${description}`, function () { + const tr = new Transaction('test', PAGE_LOAD) + tr.captureTimings = value + captureNavigation(tr) + expect(tr._start).toBe(0) + }) + }) + it('should not add API calls as resource timing spans', function () { const unMock = mockGetEntriesByType() const tr = new Transaction('test', PAGE_LOAD, {