@@ -35,6 +35,7 @@ import type {
3535 RecordingOptions ,
3636 ReplayContainer as ReplayContainerInterface ,
3737 ReplayPluginOptions ,
38+ ReplayRecordingMode ,
3839 SendReplay ,
3940 Session ,
4041} from './types' ;
@@ -64,6 +65,13 @@ export class ReplayContainer implements ReplayContainerInterface {
6465
6566 public session : Session | undefined ;
6667
68+ /**
69+ * Recording can happen in one of two modes:
70+ * * session: Record the whole session, sending it continuously
71+ * * error: Always keep the last 60s of recording, and when an error occurs, send it immediately
72+ */
73+ public mode : ReplayRecordingMode = 'session' ;
74+
6775 /**
6876 * Options to pass to `rrweb.record()`
6977 */
@@ -96,12 +104,6 @@ export class ReplayContainer implements ReplayContainerInterface {
96104 */
97105 private _isPaused : boolean = false ;
98106
99- /**
100- * Integration will wait until an error occurs before creating and sending a
101- * replay.
102- */
103- private _waitForError : boolean = false ;
104-
105107 /**
106108 * Have we attached listeners to the core SDK?
107109 * Note we have to track this as there is no way to remove instrumentation handlers.
@@ -173,7 +175,7 @@ export class ReplayContainer implements ReplayContainerInterface {
173175 // when an error will occur, so we need to keep a buffer of
174176 // replay events.
175177 if ( this . session . sampled === 'error' ) {
176- this . _waitForError = true ;
178+ this . mode = 'error' ;
177179 }
178180
179181 // setup() is generally called on page load or manually - in both cases we
@@ -203,7 +205,7 @@ export class ReplayContainer implements ReplayContainerInterface {
203205 // When running in error sampling mode, we need to overwrite `checkoutEveryNth`
204206 // Without this, it would record forever, until an error happens, which we don't want
205207 // instead, we'll always keep the last 60 seconds of replay before an error happened
206- ...( this . _waitForError && { checkoutEveryNth : 60000 } ) ,
208+ ...( this . mode === 'error' && { checkoutEveryNth : 60000 } ) ,
207209 emit : this . handleRecordingEmit ,
208210 } ) ;
209211 } catch ( err ) {
@@ -403,12 +405,12 @@ export class ReplayContainer implements ReplayContainerInterface {
403405 * processing and hand back control to caller.
404406 */
405407 addUpdate ( cb : AddUpdateCallback ) : void {
406- // We need to always run `cb` (e.g. in the case of `this._waitForError == true `)
408+ // We need to always run `cb` (e.g. in the case of `this.mode == 'error' `)
407409 const cbResult = cb ?.( ) ;
408410
409411 // If this option is turned on then we will only want to call `flush`
410412 // explicitly
411- if ( this . _waitForError ) {
413+ if ( this . mode === 'error' ) {
412414 return ;
413415 }
414416
@@ -445,7 +447,7 @@ export class ReplayContainer implements ReplayContainerInterface {
445447 // when an error occurs. Clear any state that happens before this current
446448 // checkout. This needs to happen before `addEvent()` which updates state
447449 // dependent on this reset.
448- if ( this . _waitForError && event . type === 2 ) {
450+ if ( this . mode === 'error' && event . type === 2 ) {
449451 this . setInitialState ( ) ;
450452 }
451453
@@ -471,7 +473,7 @@ export class ReplayContainer implements ReplayContainerInterface {
471473
472474 // See note above re: session start needs to reflect the most recent
473475 // checkout.
474- if ( this . _waitForError && this . session && this . _context . earliestEvent ) {
476+ if ( this . mode === 'error' && this . session && this . _context . earliestEvent ) {
475477 this . session . started = this . _context . earliestEvent ;
476478 this . _maybeSaveSession ( ) ;
477479 }
@@ -744,10 +746,10 @@ export class ReplayContainer implements ReplayContainerInterface {
744746 }
745747
746748 /**
747- * Only flush if `this._waitForError` is false.
749+ * Only flush if `this.mode === 'session'`
748750 */
749751 conditionalFlush ( ) : void {
750- if ( this . _waitForError ) {
752+ if ( this . mode === 'error' ) {
751753 return ;
752754 }
753755
0 commit comments