Skip to content

Commit

Permalink
fix(rum-core): unsampled page load transaction start must be zero (#1435
Browse files Browse the repository at this point in the history
)

* fix(rum-core): unsampled page load transaction start must be zero

* chore: change comment multiline format
  • Loading branch information
devcorpio authored Sep 26, 2023
1 parent 4d889cd commit 946c674
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ 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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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, {
Expand Down

0 comments on commit 946c674

Please sign in to comment.