@@ -47,6 +47,7 @@ import { debounce } from './util/debounce';
47
47
import { getHandleRecordingEmit } from './util/handleRecordingEmit' ;
48
48
import { isExpired } from './util/isExpired' ;
49
49
import { isSessionExpired } from './util/isSessionExpired' ;
50
+ import { logInfo } from './util/log' ;
50
51
import { sendReplay } from './util/sendReplay' ;
51
52
import type { SKIPPED } from './util/throttle' ;
52
53
import { throttle , THROTTLED } from './util/throttle' ;
@@ -249,6 +250,8 @@ export class ReplayContainer implements ReplayContainerInterface {
249
250
this . recordingMode = 'buffer' ;
250
251
}
251
252
253
+ logInfo ( `[Replay] Starting replay in ${ this . recordingMode } mode` , this . _options . _experiments . traceInternals ) ;
254
+
252
255
this . _initializeRecording ( ) ;
253
256
}
254
257
@@ -268,6 +271,8 @@ export class ReplayContainer implements ReplayContainerInterface {
268
271
throw new Error ( 'Replay buffering is in progress, call `flush()` to save the replay' ) ;
269
272
}
270
273
274
+ logInfo ( '[Replay] Starting replay in session mode' , this . _options . _experiments . traceInternals ) ;
275
+
271
276
const previousSessionId = this . session && this . session . id ;
272
277
273
278
const { session } = getSession ( {
@@ -277,6 +282,7 @@ export class ReplayContainer implements ReplayContainerInterface {
277
282
// This is intentional: create a new session-based replay when calling `start()`
278
283
sessionSampleRate : 1 ,
279
284
allowBuffering : false ,
285
+ traceInternals : this . _options . _experiments . traceInternals ,
280
286
} ) ;
281
287
282
288
session . previousSessionId = previousSessionId ;
@@ -294,6 +300,8 @@ export class ReplayContainer implements ReplayContainerInterface {
294
300
throw new Error ( 'Replay recording is already in progress' ) ;
295
301
}
296
302
303
+ logInfo ( '[Replay] Starting replay in buffer mode' , this . _options . _experiments . traceInternals ) ;
304
+
297
305
const previousSessionId = this . session && this . session . id ;
298
306
299
307
const { session } = getSession ( {
@@ -302,6 +310,7 @@ export class ReplayContainer implements ReplayContainerInterface {
302
310
currentSession : this . session ,
303
311
sessionSampleRate : 0 ,
304
312
allowBuffering : true ,
313
+ traceInternals : this . _options . _experiments . traceInternals ,
305
314
} ) ;
306
315
307
316
session . previousSessionId = previousSessionId ;
@@ -362,15 +371,10 @@ export class ReplayContainer implements ReplayContainerInterface {
362
371
}
363
372
364
373
try {
365
- if ( __DEBUG_BUILD__ ) {
366
- const msg = `[Replay] Stopping Replay${ reason ? ` triggered by ${ reason } ` : '' } ` ;
367
-
368
- // When `traceInternals` is enabled, we want to log this to the console
369
- // Else, use the regular debug output
370
- // eslint-disable-next-line
371
- const log = this . getOptions ( ) . _experiments . traceInternals ? console . warn : logger . log ;
372
- log ( msg ) ;
373
- }
374
+ logInfo (
375
+ `[Replay] Stopping Replay${ reason ? ` triggered by ${ reason } ` : '' } ` ,
376
+ this . _options . _experiments . traceInternals ,
377
+ ) ;
374
378
375
379
// We can't move `_isEnabled` after awaiting a flush, otherwise we can
376
380
// enter into an infinite loop when `stop()` is called while flushing.
@@ -403,8 +407,14 @@ export class ReplayContainer implements ReplayContainerInterface {
403
407
* not as thorough of a shutdown as `stop()`.
404
408
*/
405
409
public pause ( ) : void {
410
+ if ( this . _isPaused ) {
411
+ return ;
412
+ }
413
+
406
414
this . _isPaused = true ;
407
415
this . stopRecording ( ) ;
416
+
417
+ logInfo ( '[Replay] Pausing replay' , this . _options . _experiments . traceInternals ) ;
408
418
}
409
419
410
420
/**
@@ -414,12 +424,14 @@ export class ReplayContainer implements ReplayContainerInterface {
414
424
* new DOM checkout.`
415
425
*/
416
426
public resume ( ) : void {
417
- if ( ! this . _loadAndCheckSession ( ) ) {
427
+ if ( ! this . _isPaused || ! this . _loadAndCheckSession ( ) ) {
418
428
return ;
419
429
}
420
430
421
431
this . _isPaused = false ;
422
432
this . startRecording ( ) ;
433
+
434
+ logInfo ( '[Replay] Resuming replay' , this . _options . _experiments . traceInternals ) ;
423
435
}
424
436
425
437
/**
@@ -436,9 +448,7 @@ export class ReplayContainer implements ReplayContainerInterface {
436
448
437
449
const activityTime = Date . now ( ) ;
438
450
439
- // eslint-disable-next-line no-console
440
- const log = this . getOptions ( ) . _experiments . traceInternals ? console . info : logger . info ;
441
- __DEBUG_BUILD__ && log ( `[Replay] Converting buffer to session, starting at ${ activityTime } ` ) ;
451
+ logInfo ( '[Replay] Converting buffer to session' , this . _options . _experiments . traceInternals ) ;
442
452
443
453
// Allow flush to complete before resuming as a session recording, otherwise
444
454
// the checkout from `startRecording` may be included in the payload.
@@ -746,6 +756,7 @@ export class ReplayContainer implements ReplayContainerInterface {
746
756
currentSession : this . session ,
747
757
sessionSampleRate : this . _options . sessionSampleRate ,
748
758
allowBuffering : this . _options . errorSampleRate > 0 || this . recordingMode === 'buffer' ,
759
+ traceInternals : this . _options . _experiments . traceInternals ,
749
760
} ) ;
750
761
751
762
// If session was newly created (i.e. was not loaded from storage), then
@@ -762,7 +773,7 @@ export class ReplayContainer implements ReplayContainerInterface {
762
773
this . session = session ;
763
774
764
775
if ( ! this . session . sampled ) {
765
- void this . stop ( 'session unsampled ' ) ;
776
+ void this . stop ( 'session not refreshed ' ) ;
766
777
return false ;
767
778
}
768
779
@@ -904,7 +915,7 @@ export class ReplayContainer implements ReplayContainerInterface {
904
915
// If the user has come back to the page within SESSION_IDLE_PAUSE_DURATION
905
916
// ms, we will re-use the existing session, otherwise create a new
906
917
// session
907
- __DEBUG_BUILD__ && logger . log ( '[Replay] Document has become active, but session has expired' ) ;
918
+ logInfo ( '[Replay] Document has become active, but session has expired' ) ;
908
919
return ;
909
920
}
910
921
@@ -919,7 +930,7 @@ export class ReplayContainer implements ReplayContainerInterface {
919
930
*/
920
931
private _triggerFullSnapshot ( checkout = true ) : void {
921
932
try {
922
- __DEBUG_BUILD__ && logger . log ( '[Replay] Taking full rrweb snapshot' ) ;
933
+ logInfo ( '[Replay] Taking full rrweb snapshot' ) ;
923
934
record . takeFullSnapshot ( checkout ) ;
924
935
} catch ( err ) {
925
936
this . _handleException ( err ) ;
@@ -1121,13 +1132,10 @@ export class ReplayContainer implements ReplayContainerInterface {
1121
1132
// If session is too short, or too long (allow some wiggle room over maxSessionLife), do not send it
1122
1133
// This _should_ not happen, but it may happen if flush is triggered due to a page activity change or similar
1123
1134
if ( duration < this . _options . minReplayDuration || duration > this . timeouts . maxSessionLife + 5_000 ) {
1124
- // eslint-disable-next-line no-console
1125
- const log = this . getOptions ( ) . _experiments . traceInternals ? console . warn : logger . warn ;
1126
- __DEBUG_BUILD__ &&
1127
- log (
1128
- `[Replay] Session duration (${ Math . floor ( duration / 1000 ) } s) is too short or too long, not sending replay.` ,
1129
- ) ;
1130
-
1135
+ logInfo (
1136
+ `[Replay] Session duration (${ Math . floor ( duration / 1000 ) } s) is too short or too long, not sending replay.` ,
1137
+ this . _options . _experiments . traceInternals ,
1138
+ ) ;
1131
1139
return ;
1132
1140
}
1133
1141
0 commit comments