-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
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(); | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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?