@@ -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' ;
@@ -239,6 +240,8 @@ export class ReplayContainer implements ReplayContainerInterface {
239
240
this . recordingMode = 'buffer' ;
240
241
}
241
242
243
+ logInfo ( `[Replay] Starting replay in ${ this . recordingMode } mode` , this . _options . _experiments . traceInternals ) ;
244
+
242
245
this . _initializeRecording ( ) ;
243
246
}
244
247
@@ -258,6 +261,8 @@ export class ReplayContainer implements ReplayContainerInterface {
258
261
throw new Error ( 'Replay buffering is in progress, call `flush()` to save the replay' ) ;
259
262
}
260
263
264
+ logInfo ( '[Replay] Starting replay in session mode' , this . _options . _experiments . traceInternals ) ;
265
+
261
266
const previousSessionId = this . session && this . session . id ;
262
267
263
268
const { session } = getSession ( {
@@ -267,6 +272,7 @@ export class ReplayContainer implements ReplayContainerInterface {
267
272
// This is intentional: create a new session-based replay when calling `start()`
268
273
sessionSampleRate : 1 ,
269
274
allowBuffering : false ,
275
+ traceInternals : this . _options . _experiments . traceInternals ,
270
276
} ) ;
271
277
272
278
session . previousSessionId = previousSessionId ;
@@ -284,6 +290,8 @@ export class ReplayContainer implements ReplayContainerInterface {
284
290
throw new Error ( 'Replay recording is already in progress' ) ;
285
291
}
286
292
293
+ logInfo ( '[Replay] Starting replay in buffer mode' , this . _options . _experiments . traceInternals ) ;
294
+
287
295
const previousSessionId = this . session && this . session . id ;
288
296
289
297
const { session } = getSession ( {
@@ -292,6 +300,7 @@ export class ReplayContainer implements ReplayContainerInterface {
292
300
currentSession : this . session ,
293
301
sessionSampleRate : 0 ,
294
302
allowBuffering : true ,
303
+ traceInternals : this . _options . _experiments . traceInternals ,
295
304
} ) ;
296
305
297
306
session . previousSessionId = previousSessionId ;
@@ -352,15 +361,10 @@ export class ReplayContainer implements ReplayContainerInterface {
352
361
}
353
362
354
363
try {
355
- if ( __DEBUG_BUILD__ ) {
356
- const msg = `[Replay] Stopping Replay${ reason ? ` triggered by ${ reason } ` : '' } ` ;
357
-
358
- // When `traceInternals` is enabled, we want to log this to the console
359
- // Else, use the regular debug output
360
- // eslint-disable-next-line
361
- const log = this . getOptions ( ) . _experiments . traceInternals ? console . warn : logger . log ;
362
- log ( msg ) ;
363
- }
364
+ logInfo (
365
+ `[Replay] Stopping Replay${ reason ? ` triggered by ${ reason } ` : '' } ` ,
366
+ this . _options . _experiments . traceInternals ,
367
+ ) ;
364
368
365
369
// We can't move `_isEnabled` after awaiting a flush, otherwise we can
366
370
// enter into an infinite loop when `stop()` is called while flushing.
@@ -393,8 +397,14 @@ export class ReplayContainer implements ReplayContainerInterface {
393
397
* not as thorough of a shutdown as `stop()`.
394
398
*/
395
399
public pause ( ) : void {
400
+ if ( this . _isPaused ) {
401
+ return ;
402
+ }
403
+
396
404
this . _isPaused = true ;
397
405
this . stopRecording ( ) ;
406
+
407
+ logInfo ( '[Replay] Pausing replay' , this . _options . _experiments . traceInternals ) ;
398
408
}
399
409
400
410
/**
@@ -404,12 +414,14 @@ export class ReplayContainer implements ReplayContainerInterface {
404
414
* new DOM checkout.`
405
415
*/
406
416
public resume ( ) : void {
407
- if ( ! this . _loadAndCheckSession ( ) ) {
417
+ if ( ! this . _isPaused || ! this . _loadAndCheckSession ( ) ) {
408
418
return ;
409
419
}
410
420
411
421
this . _isPaused = false ;
412
422
this . startRecording ( ) ;
423
+
424
+ logInfo ( '[Replay] Resuming replay' , this . _options . _experiments . traceInternals ) ;
413
425
}
414
426
415
427
/**
@@ -426,9 +438,7 @@ export class ReplayContainer implements ReplayContainerInterface {
426
438
427
439
const activityTime = Date . now ( ) ;
428
440
429
- // eslint-disable-next-line no-console
430
- const log = this . getOptions ( ) . _experiments . traceInternals ? console . info : logger . info ;
431
- __DEBUG_BUILD__ && log ( `[Replay] Converting buffer to session, starting at ${ activityTime } ` ) ;
441
+ logInfo ( '[Replay] Converting buffer to session' , this . _options . _experiments . traceInternals ) ;
432
442
433
443
// Allow flush to complete before resuming as a session recording, otherwise
434
444
// the checkout from `startRecording` may be included in the payload.
@@ -736,6 +746,7 @@ export class ReplayContainer implements ReplayContainerInterface {
736
746
currentSession : this . session ,
737
747
sessionSampleRate : this . _options . sessionSampleRate ,
738
748
allowBuffering : this . _options . errorSampleRate > 0 || this . recordingMode === 'buffer' ,
749
+ traceInternals : this . _options . _experiments . traceInternals ,
739
750
} ) ;
740
751
741
752
// If session was newly created (i.e. was not loaded from storage), then
@@ -752,7 +763,7 @@ export class ReplayContainer implements ReplayContainerInterface {
752
763
this . session = session ;
753
764
754
765
if ( ! this . session . sampled ) {
755
- void this . stop ( 'session unsampled ' ) ;
766
+ void this . stop ( 'session not refreshed ' ) ;
756
767
return false ;
757
768
}
758
769
@@ -894,7 +905,7 @@ export class ReplayContainer implements ReplayContainerInterface {
894
905
// If the user has come back to the page within SESSION_IDLE_PAUSE_DURATION
895
906
// ms, we will re-use the existing session, otherwise create a new
896
907
// session
897
- __DEBUG_BUILD__ && logger . log ( '[Replay] Document has become active, but session has expired' ) ;
908
+ logInfo ( '[Replay] Document has become active, but session has expired' ) ;
898
909
return ;
899
910
}
900
911
@@ -909,7 +920,7 @@ export class ReplayContainer implements ReplayContainerInterface {
909
920
*/
910
921
private _triggerFullSnapshot ( checkout = true ) : void {
911
922
try {
912
- __DEBUG_BUILD__ && logger . log ( '[Replay] Taking full rrweb snapshot' ) ;
923
+ logInfo ( '[Replay] Taking full rrweb snapshot' ) ;
913
924
record . takeFullSnapshot ( checkout ) ;
914
925
} catch ( err ) {
915
926
this . _handleException ( err ) ;
@@ -1111,13 +1122,10 @@ export class ReplayContainer implements ReplayContainerInterface {
1111
1122
// If session is too short, or too long (allow some wiggle room over maxSessionLife), do not send it
1112
1123
// This _should_ not happen, but it may happen if flush is triggered due to a page activity change or similar
1113
1124
if ( duration < this . _options . minReplayDuration || duration > this . timeouts . maxSessionLife + 5_000 ) {
1114
- // eslint-disable-next-line no-console
1115
- const log = this . getOptions ( ) . _experiments . traceInternals ? console . warn : logger . warn ;
1116
- __DEBUG_BUILD__ &&
1117
- log (
1118
- `[Replay] Session duration (${ Math . floor ( duration / 1000 ) } s) is too short or too long, not sending replay.` ,
1119
- ) ;
1120
-
1125
+ logInfo (
1126
+ `[Replay] Session duration (${ Math . floor ( duration / 1000 ) } s) is too short or too long, not sending replay.` ,
1127
+ this . _options . _experiments . traceInternals ,
1128
+ ) ;
1121
1129
return ;
1122
1130
}
1123
1131
0 commit comments