@@ -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' ;
@@ -239,6 +240,8 @@ export class ReplayContainer implements ReplayContainerInterface {
239240 this . recordingMode = 'buffer' ;
240241 }
241242
243+ logInfo ( `[Replay] Starting replay in ${ this . recordingMode } mode` , this . _options . _experiments . traceInternals ) ;
244+
242245 this . _initializeRecording ( ) ;
243246 }
244247
@@ -258,6 +261,8 @@ export class ReplayContainer implements ReplayContainerInterface {
258261 throw new Error ( 'Replay buffering is in progress, call `flush()` to save the replay' ) ;
259262 }
260263
264+ logInfo ( '[Replay] Starting replay in session mode' , this . _options . _experiments . traceInternals ) ;
265+
261266 const previousSessionId = this . session && this . session . id ;
262267
263268 const { session } = getSession ( {
@@ -267,6 +272,7 @@ export class ReplayContainer implements ReplayContainerInterface {
267272 // This is intentional: create a new session-based replay when calling `start()`
268273 sessionSampleRate : 1 ,
269274 allowBuffering : false ,
275+ traceInternals : this . _options . _experiments . traceInternals ,
270276 } ) ;
271277
272278 session . previousSessionId = previousSessionId ;
@@ -284,6 +290,8 @@ export class ReplayContainer implements ReplayContainerInterface {
284290 throw new Error ( 'Replay recording is already in progress' ) ;
285291 }
286292
293+ logInfo ( '[Replay] Starting replay in buffer mode' , this . _options . _experiments . traceInternals ) ;
294+
287295 const previousSessionId = this . session && this . session . id ;
288296
289297 const { session } = getSession ( {
@@ -292,6 +300,7 @@ export class ReplayContainer implements ReplayContainerInterface {
292300 currentSession : this . session ,
293301 sessionSampleRate : 0 ,
294302 allowBuffering : true ,
303+ traceInternals : this . _options . _experiments . traceInternals ,
295304 } ) ;
296305
297306 session . previousSessionId = previousSessionId ;
@@ -352,15 +361,10 @@ export class ReplayContainer implements ReplayContainerInterface {
352361 }
353362
354363 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+ ) ;
364368
365369 // We can't move `_isEnabled` after awaiting a flush, otherwise we can
366370 // enter into an infinite loop when `stop()` is called while flushing.
@@ -393,8 +397,14 @@ export class ReplayContainer implements ReplayContainerInterface {
393397 * not as thorough of a shutdown as `stop()`.
394398 */
395399 public pause ( ) : void {
400+ if ( this . _isPaused ) {
401+ return ;
402+ }
403+
396404 this . _isPaused = true ;
397405 this . stopRecording ( ) ;
406+
407+ logInfo ( '[Replay] Pausing replay' , this . _options . _experiments . traceInternals ) ;
398408 }
399409
400410 /**
@@ -404,12 +414,14 @@ export class ReplayContainer implements ReplayContainerInterface {
404414 * new DOM checkout.`
405415 */
406416 public resume ( ) : void {
407- if ( ! this . _loadAndCheckSession ( ) ) {
417+ if ( ! this . _isPaused || ! this . _loadAndCheckSession ( ) ) {
408418 return ;
409419 }
410420
411421 this . _isPaused = false ;
412422 this . startRecording ( ) ;
423+
424+ logInfo ( '[Replay] Resuming replay' , this . _options . _experiments . traceInternals ) ;
413425 }
414426
415427 /**
@@ -426,9 +438,7 @@ export class ReplayContainer implements ReplayContainerInterface {
426438
427439 const activityTime = Date . now ( ) ;
428440
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 ) ;
432442
433443 // Allow flush to complete before resuming as a session recording, otherwise
434444 // the checkout from `startRecording` may be included in the payload.
@@ -736,6 +746,7 @@ export class ReplayContainer implements ReplayContainerInterface {
736746 currentSession : this . session ,
737747 sessionSampleRate : this . _options . sessionSampleRate ,
738748 allowBuffering : this . _options . errorSampleRate > 0 || this . recordingMode === 'buffer' ,
749+ traceInternals : this . _options . _experiments . traceInternals ,
739750 } ) ;
740751
741752 // If session was newly created (i.e. was not loaded from storage), then
@@ -752,7 +763,7 @@ export class ReplayContainer implements ReplayContainerInterface {
752763 this . session = session ;
753764
754765 if ( ! this . session . sampled ) {
755- void this . stop ( 'session unsampled ' ) ;
766+ void this . stop ( 'session not refreshed ' ) ;
756767 return false ;
757768 }
758769
@@ -894,7 +905,7 @@ export class ReplayContainer implements ReplayContainerInterface {
894905 // If the user has come back to the page within SESSION_IDLE_PAUSE_DURATION
895906 // ms, we will re-use the existing session, otherwise create a new
896907 // 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' ) ;
898909 return ;
899910 }
900911
@@ -909,7 +920,7 @@ export class ReplayContainer implements ReplayContainerInterface {
909920 */
910921 private _triggerFullSnapshot ( checkout = true ) : void {
911922 try {
912- __DEBUG_BUILD__ && logger . log ( '[Replay] Taking full rrweb snapshot' ) ;
923+ logInfo ( '[Replay] Taking full rrweb snapshot' ) ;
913924 record . takeFullSnapshot ( checkout ) ;
914925 } catch ( err ) {
915926 this . _handleException ( err ) ;
@@ -1111,13 +1122,10 @@ export class ReplayContainer implements ReplayContainerInterface {
11111122 // If session is too short, or too long (allow some wiggle room over maxSessionLife), do not send it
11121123 // This _should_ not happen, but it may happen if flush is triggered due to a page activity change or similar
11131124 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+ ) ;
11211129 return ;
11221130 }
11231131
0 commit comments