Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 1.8k
ref(replay): Move earliest timestamp tracking to eventBuffer#7983
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -118,7 +118,6 @@ export class ReplayContainer implements ReplayContainerInterface { | ||
| errorIds: new Set(), | ||
| traceIds: new Set(), | ||
| urls: [], | ||
| earliestEvent: null, | ||
| initialTimestamp: Date.now(), | ||
| initialUrl: '', | ||
| }; | ||
| @@ -819,22 +818,35 @@ export class ReplayContainer implements ReplayContainerInterface { | ||
| this._context.errorIds.clear(); | ||
| this._context.traceIds.clear(); | ||
| this._context.urls = []; | ||
| this._context.earliestEvent = null; | ||
| } | ||
| /** Update the initial timestamp based on the buffer content. */ | ||
| private _updateInitialTimestampFromEventBuffer(): void { | ||
| const { session, eventBuffer } = this; | ||
| if (!session || !eventBuffer) { | ||
| return; | ||
| } | ||
| // we only ever update this on the initial segment | ||
| if (session.segmentId) { | ||
| return; | ||
| } | ||
| const earliestEvent = eventBuffer.getEarliestTimestamp(); | ||
| if (earliestEvent && earliestEvent < this._context.initialTimestamp) { | ||
| this._context.initialTimestamp = earliestEvent; | ||
| } | ||
| } | ||
| /** | ||
| * Return and clear _context | ||
| */ | ||
| private _popEventContext(): PopEventContext { | ||
| if (this._context.earliestEvent && this._context.earliestEvent < this._context.initialTimestamp) { | ||
| this._context.initialTimestamp = this._context.earliestEvent; | ||
| } | ||
| const _context = { | ||
| initialTimestamp: this._context.initialTimestamp, | ||
| initialUrl: this._context.initialUrl, | ||
| errorIds: Array.from(this._context.errorIds).filter(Boolean), | ||
MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Noticed these here, we actually check if the ids are non-empty before adding them to the set, so IMHO we do not need these checks anymore. | ||
| traceIds: Array.from(this._context.traceIds).filter(Boolean), | ||
| errorIds: Array.from(this._context.errorIds), | ||
| traceIds: Array.from(this._context.traceIds), | ||
| urls: this._context.urls, | ||
| }; | ||
| @@ -873,6 +885,9 @@ export class ReplayContainer implements ReplayContainerInterface { | ||
| } | ||
| try { | ||
| // This uses the data from the eventBuffer, so we need to call this before `finish() | ||
| this._updateInitialTimestampFromEventBuffer(); | ||
| // Note this empties the event buffer regardless of outcome of sending replay | ||
| const recordingData = await this.eventBuffer.finish(); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| /** | ||
| * Converts a timestamp to ms, if it was in s, or keeps it as ms. | ||
| */ | ||
| export function timestampToMs(timestamp: number): number { | ||
| const isMs = timestamp > 9999999999; | ||
| return isMs ? timestamp : timestamp * 1000; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not do the same thing in array buffer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My thought was that we write this much more often than we read it (we really only read it on the first checkout), so felt it would be more efficient to do work only at read time then?