@@ -47,6 +47,7 @@ import { debounce } from './util/debounce';
4747import { getHandleRecordingEmit } from './util/handleRecordingEmit' ;
4848import { isExpired } from './util/isExpired' ;
4949import { isSessionExpired } from './util/isSessionExpired' ;
50+ import { logInfo } from './util/log' ;
5051import { sendReplay } from './util/sendReplay' ;
5152import type { SKIPPED } from './util/throttle' ;
5253import { throttle , THROTTLED } from './util/throttle' ;
@@ -249,6 +250,8 @@ export class ReplayContainer implements ReplayContainerInterface {
249250 this . recordingMode = 'buffer' ;
250251 }
251252
253+ logInfo ( `[Replay] Starting replay in ${ this . recordingMode } mode` , this . _options . _experiments . traceInternals ) ;
254+
252255 this . _initializeRecording ( ) ;
253256 }
254257
@@ -268,6 +271,8 @@ export class ReplayContainer implements ReplayContainerInterface {
268271 throw new Error ( 'Replay buffering is in progress, call `flush()` to save the replay' ) ;
269272 }
270273
274+ logInfo ( '[Replay] Starting replay in session mode' , this . _options . _experiments . traceInternals ) ;
275+
271276 const previousSessionId = this . session && this . session . id ;
272277
273278 const { session } = getSession ( {
@@ -277,6 +282,7 @@ export class ReplayContainer implements ReplayContainerInterface {
277282 // This is intentional: create a new session-based replay when calling `start()`
278283 sessionSampleRate : 1 ,
279284 allowBuffering : false ,
285+ traceInternals : this . _options . _experiments . traceInternals ,
280286 } ) ;
281287
282288 session . previousSessionId = previousSessionId ;
@@ -294,6 +300,8 @@ export class ReplayContainer implements ReplayContainerInterface {
294300 throw new Error ( 'Replay recording is already in progress' ) ;
295301 }
296302
303+ logInfo ( '[Replay] Starting replay in buffer mode' , this . _options . _experiments . traceInternals ) ;
304+
297305 const previousSessionId = this . session && this . session . id ;
298306
299307 const { session } = getSession ( {
@@ -302,6 +310,7 @@ export class ReplayContainer implements ReplayContainerInterface {
302310 currentSession : this . session ,
303311 sessionSampleRate : 0 ,
304312 allowBuffering : true ,
313+ traceInternals : this . _options . _experiments . traceInternals ,
305314 } ) ;
306315
307316 session . previousSessionId = previousSessionId ;
@@ -362,15 +371,10 @@ export class ReplayContainer implements ReplayContainerInterface {
362371 }
363372
364373 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+ ) ;
374378
375379 // We can't move `_isEnabled` after awaiting a flush, otherwise we can
376380 // enter into an infinite loop when `stop()` is called while flushing.
@@ -403,8 +407,14 @@ export class ReplayContainer implements ReplayContainerInterface {
403407 * not as thorough of a shutdown as `stop()`.
404408 */
405409 public pause ( ) : void {
410+ if ( this . _isPaused ) {
411+ return ;
412+ }
413+
406414 this . _isPaused = true ;
407415 this . stopRecording ( ) ;
416+
417+ logInfo ( '[Replay] Pausing replay' , this . _options . _experiments . traceInternals ) ;
408418 }
409419
410420 /**
@@ -414,12 +424,14 @@ export class ReplayContainer implements ReplayContainerInterface {
414424 * new DOM checkout.`
415425 */
416426 public resume ( ) : void {
417- if ( ! this . _loadAndCheckSession ( ) ) {
427+ if ( ! this . _isPaused || ! this . _loadAndCheckSession ( ) ) {
418428 return ;
419429 }
420430
421431 this . _isPaused = false ;
422432 this . startRecording ( ) ;
433+
434+ logInfo ( '[Replay] Resuming replay' , this . _options . _experiments . traceInternals ) ;
423435 }
424436
425437 /**
@@ -436,9 +448,7 @@ export class ReplayContainer implements ReplayContainerInterface {
436448
437449 const activityTime = Date . now ( ) ;
438450
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 ) ;
442452
443453 // Allow flush to complete before resuming as a session recording, otherwise
444454 // the checkout from `startRecording` may be included in the payload.
@@ -746,6 +756,7 @@ export class ReplayContainer implements ReplayContainerInterface {
746756 currentSession : this . session ,
747757 sessionSampleRate : this . _options . sessionSampleRate ,
748758 allowBuffering : this . _options . errorSampleRate > 0 || this . recordingMode === 'buffer' ,
759+ traceInternals : this . _options . _experiments . traceInternals ,
749760 } ) ;
750761
751762 // If session was newly created (i.e. was not loaded from storage), then
@@ -762,7 +773,7 @@ export class ReplayContainer implements ReplayContainerInterface {
762773 this . session = session ;
763774
764775 if ( ! this . session . sampled ) {
765- void this . stop ( 'session unsampled ' ) ;
776+ void this . stop ( 'session not refreshed ' ) ;
766777 return false ;
767778 }
768779
@@ -904,7 +915,7 @@ export class ReplayContainer implements ReplayContainerInterface {
904915 // If the user has come back to the page within SESSION_IDLE_PAUSE_DURATION
905916 // ms, we will re-use the existing session, otherwise create a new
906917 // 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' ) ;
908919 return ;
909920 }
910921
@@ -919,7 +930,7 @@ export class ReplayContainer implements ReplayContainerInterface {
919930 */
920931 private _triggerFullSnapshot ( checkout = true ) : void {
921932 try {
922- __DEBUG_BUILD__ && logger . log ( '[Replay] Taking full rrweb snapshot' ) ;
933+ logInfo ( '[Replay] Taking full rrweb snapshot' ) ;
923934 record . takeFullSnapshot ( checkout ) ;
924935 } catch ( err ) {
925936 this . _handleException ( err ) ;
@@ -1121,13 +1132,10 @@ export class ReplayContainer implements ReplayContainerInterface {
11211132 // If session is too short, or too long (allow some wiggle room over maxSessionLife), do not send it
11221133 // This _should_ not happen, but it may happen if flush is triggered due to a page activity change or similar
11231134 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+ ) ;
11311139 return ;
11321140 }
11331141
0 commit comments