Skip to content

Commit

Permalink
Don't truncate the page state start time
Browse files Browse the repository at this point in the history
  • Loading branch information
amortemousque committed May 12, 2023
1 parent bfdfcb3 commit b3cc4d6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
12 changes: 10 additions & 2 deletions packages/rum-core/src/domain/contexts/pageStateHistory.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,18 @@ describe('pageStateHistory', () => {
clock.tick(10)
pageStateHistory.addPageState(PageState.TERMINATED)

expect(pageStateHistory.findAll(15 as RelativeTime, 20 as RelativeTime)).toEqual([
/*
page state time 0 10 20 30 40
event time 15<-------->35
*/
const event = {
startTime: 15 as RelativeTime,
duration: 20 as RelativeTime,
}
expect(pageStateHistory.findAll(event.startTime, event.duration)).toEqual([
{
state: PageState.PASSIVE,
start: 0 as ServerDuration,
start: -5000000 as ServerDuration,
},
{
state: PageState.HIDDEN,
Expand Down
8 changes: 3 additions & 5 deletions packages/rum-core/src/domain/contexts/pageStateHistory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,12 @@ export function startPageStateHistory(

for (let index = pageStateEntries.length - 1; index >= limit; index--) {
const pageState = pageStateEntries[index]
// correct the start time to allays be higher or equal to the event start time
const correctedStartTime = eventStartTime > pageState.startTime ? eventStartTime : pageState.startTime
// recenter the start time to be relative to the event start time (ex: to be relative to the view start time)
const recenteredStartTime = elapsed(eventStartTime, correctedStartTime)
// compute the start time relative to the event start time (ex: to be relative to the view start time)
const relativeStartTime = elapsed(eventStartTime, pageState.startTime)

pageStateServerEntries.push({
state: pageState.state,
start: toServerDuration(recenteredStartTime),
start: toServerDuration(relativeStartTime),
})
}

Expand Down

0 comments on commit b3cc4d6

Please sign in to comment.