-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
feat(replay): Change flush()
API to record current event buffer
#7743
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
Show all changes
8 commits
Select commit
Hold shift + click to select a range
bf5d4f1
ref(replay): Add `capture()` API to record current event buffer
billyvg d64d8b2
rename and change options
billyvg 8f8784d
update comments
billyvg adcf18d
flush immediate in session mode as well
billyvg 893d0e3
update comment
billyvg b4cd077
stopRecording + test
billyvg bd981f9
lint
billyvg 8c1d9c7
review change
billyvg 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ import type { | |
RecordingOptions, | ||
ReplayContainer as ReplayContainerInterface, | ||
ReplayPluginOptions, | ||
SendBufferedReplayOptions, | ||
Session, | ||
Timeouts, | ||
} from './types'; | ||
|
@@ -216,17 +217,18 @@ export class ReplayContainer implements ReplayContainerInterface { | |
|
||
/** | ||
* Stops the recording, if it was running. | ||
* Returns true if it was stopped, else false. | ||
* | ||
* Returns true if it was previously stopped, or is now stopped, | ||
* otherwise false. | ||
*/ | ||
public stopRecording(): boolean { | ||
try { | ||
if (this._stopRecording) { | ||
this._stopRecording(); | ||
this._stopRecording = undefined; | ||
return true; | ||
} | ||
|
||
return false; | ||
return true; | ||
mydea marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} catch (err) { | ||
this._handleException(err); | ||
return false; | ||
|
@@ -289,6 +291,38 @@ export class ReplayContainer implements ReplayContainerInterface { | |
this.startRecording(); | ||
} | ||
|
||
/** | ||
* If not in "session" recording mode, flush event buffer which will create a new replay. | ||
* Unless `continueRecording` is false, the replay will continue to record and | ||
* behave as a "session"-based replay. | ||
* | ||
* Otherwise, queue up a flush. | ||
*/ | ||
public async sendBufferedReplayOrFlush({ continueRecording = true }: SendBufferedReplayOptions = {}): Promise<void> { | ||
if (this.recordingMode === 'session') { | ||
return this.flushImmediate(); | ||
} | ||
|
||
// Allow flush to complete before resuming as a session recording, otherwise | ||
// the checkout from `startRecording` may be included in the payload. | ||
// Prefer to keep the error replay as a separate (and smaller) segment | ||
// than the session replay. | ||
await this.flushImmediate(); | ||
|
||
const hasStoppedRecording = this.stopRecording(); | ||
|
||
if (!continueRecording || !hasStoppedRecording) { | ||
return; | ||
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. Hmm, do we need to still stop the recording here? 🤔 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. May be simplified to: if (!continueRecording || !hasStoppedRecording) {
return;
}
// Reset all ... |
||
} | ||
|
||
// Re-start recording, but in "session" recording mode | ||
|
||
// Reset all "capture on error" configuration before | ||
// starting a new recording | ||
this.recordingMode = 'session'; | ||
this.startRecording(); | ||
} | ||
|
||
/** | ||
* We want to batch uploads of replay events. Save events only if | ||
* `<flushMinDelay>` milliseconds have elapsed since the last event | ||
|
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.
Uh oh!
There was an error while loading. Please reload this page.