@@ -35,6 +35,7 @@ import type {
35
35
RecordingOptions ,
36
36
ReplayContainer as ReplayContainerInterface ,
37
37
ReplayPluginOptions ,
38
+ ReplayRecordingMode ,
38
39
SendReplay ,
39
40
Session ,
40
41
} from './types' ;
@@ -64,6 +65,13 @@ export class ReplayContainer implements ReplayContainerInterface {
64
65
65
66
public session : Session | undefined ;
66
67
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 recordingMode : ReplayRecordingMode = 'session' ;
74
+
67
75
/**
68
76
* Options to pass to `rrweb.record()`
69
77
*/
@@ -96,12 +104,6 @@ export class ReplayContainer implements ReplayContainerInterface {
96
104
*/
97
105
private _isPaused : boolean = false ;
98
106
99
- /**
100
- * Integration will wait until an error occurs before creating and sending a
101
- * replay.
102
- */
103
- private _waitForError : boolean = false ;
104
-
105
107
/**
106
108
* Have we attached listeners to the core SDK?
107
109
* Note we have to track this as there is no way to remove instrumentation handlers.
@@ -173,7 +175,7 @@ export class ReplayContainer implements ReplayContainerInterface {
173
175
// when an error will occur, so we need to keep a buffer of
174
176
// replay events.
175
177
if ( this . session . sampled === 'error' ) {
176
- this . _waitForError = true ;
178
+ this . recordingMode = 'error' ;
177
179
}
178
180
179
181
// setup() is generally called on page load or manually - in both cases we
@@ -203,7 +205,7 @@ export class ReplayContainer implements ReplayContainerInterface {
203
205
// When running in error sampling mode, we need to overwrite `checkoutEveryNth`
204
206
// Without this, it would record forever, until an error happens, which we don't want
205
207
// instead, we'll always keep the last 60 seconds of replay before an error happened
206
- ...( this . _waitForError && { checkoutEveryNth : 60000 } ) ,
208
+ ...( this . recordingMode === 'error' && { checkoutEveryNth : 60000 } ) ,
207
209
emit : this . handleRecordingEmit ,
208
210
} ) ;
209
211
} catch ( err ) {
@@ -403,12 +405,12 @@ export class ReplayContainer implements ReplayContainerInterface {
403
405
* processing and hand back control to caller.
404
406
*/
405
407
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.recordingMode == 'error' `)
407
409
const cbResult = cb ?.( ) ;
408
410
409
411
// If this option is turned on then we will only want to call `flush`
410
412
// explicitly
411
- if ( this . _waitForError ) {
413
+ if ( this . recordingMode === 'error' ) {
412
414
return ;
413
415
}
414
416
@@ -445,7 +447,7 @@ export class ReplayContainer implements ReplayContainerInterface {
445
447
// when an error occurs. Clear any state that happens before this current
446
448
// checkout. This needs to happen before `addEvent()` which updates state
447
449
// dependent on this reset.
448
- if ( this . _waitForError && event . type === 2 ) {
450
+ if ( this . recordingMode === 'error' && event . type === 2 ) {
449
451
this . setInitialState ( ) ;
450
452
}
451
453
@@ -471,7 +473,7 @@ export class ReplayContainer implements ReplayContainerInterface {
471
473
472
474
// See note above re: session start needs to reflect the most recent
473
475
// checkout.
474
- if ( this . _waitForError && this . session && this . _context . earliestEvent ) {
476
+ if ( this . recordingMode === 'error' && this . session && this . _context . earliestEvent ) {
475
477
this . session . started = this . _context . earliestEvent ;
476
478
this . _maybeSaveSession ( ) ;
477
479
}
@@ -744,10 +746,10 @@ export class ReplayContainer implements ReplayContainerInterface {
744
746
}
745
747
746
748
/**
747
- * Only flush if `this._waitForError` is false.
749
+ * Only flush if `this.recordingMode === 'session'`
748
750
*/
749
751
conditionalFlush ( ) : void {
750
- if ( this . _waitForError ) {
752
+ if ( this . recordingMode === 'error' ) {
751
753
return ;
752
754
}
753
755
0 commit comments