@@ -4,13 +4,7 @@ import { captureException, getCurrentHub } from '@sentry/core';
44import type { Breadcrumb , ReplayRecordingMode } from '@sentry/types' ;
55import { logger } from '@sentry/utils' ;
66
7- import {
8- ERROR_CHECKOUT_TIME ,
9- MAX_SESSION_LIFE ,
10- SESSION_IDLE_DURATION ,
11- VISIBILITY_CHANGE_TIMEOUT ,
12- WINDOW ,
13- } from './constants' ;
7+ import { ERROR_CHECKOUT_TIME , MAX_SESSION_LIFE , SESSION_IDLE_DURATION , WINDOW } from './constants' ;
148import { setupPerformanceObserver } from './coreHandlers/performanceObserver' ;
159import { createEventBuffer } from './eventBuffer' ;
1610import { getSession } from './session/getSession' ;
@@ -60,6 +54,12 @@ export class ReplayContainer implements ReplayContainerInterface {
6054 */
6155 public recordingMode : ReplayRecordingMode = 'session' ;
6256
57+ /** These are here so we can overwrite them in tests etc. */
58+ public timeouts = {
59+ sessionIdle : SESSION_IDLE_DURATION ,
60+ maxSessionLife : MAX_SESSION_LIFE ,
61+ } ;
62+
6363 /**
6464 * Options to pass to `rrweb.record()`
6565 */
@@ -367,22 +367,22 @@ export class ReplayContainer implements ReplayContainerInterface {
367367 * Returns true if session is not expired, false otherwise.
368368 * @hidden
369369 */
370- public checkAndHandleExpiredSession ( expiry ?: number ) : boolean | void {
370+ public checkAndHandleExpiredSession ( ) : boolean | void {
371371 const oldSessionId = this . getSessionId ( ) ;
372372
373373 // Prevent starting a new session if the last user activity is older than
374374 // MAX_SESSION_LIFE. Otherwise non-user activity can trigger a new
375375 // session+recording. This creates noisy replays that do not have much
376376 // content in them.
377- if ( this . _lastActivity && isExpired ( this . _lastActivity , MAX_SESSION_LIFE ) ) {
377+ if ( this . _lastActivity && isExpired ( this . _lastActivity , this . timeouts . maxSessionLife ) ) {
378378 // Pause recording
379379 this . pause ( ) ;
380380 return ;
381381 }
382382
383383 // --- There is recent user activity --- //
384384 // This will create a new session if expired, based on expiry length
385- if ( ! this . _loadAndCheckSession ( expiry ) ) {
385+ if ( ! this . _loadAndCheckSession ( ) ) {
386386 return ;
387387 }
388388
@@ -412,9 +412,10 @@ export class ReplayContainer implements ReplayContainerInterface {
412412 * Loads (or refreshes) the current session.
413413 * Returns false if session is not recorded.
414414 */
415- private _loadAndCheckSession ( expiry = SESSION_IDLE_DURATION ) : boolean {
415+ private _loadAndCheckSession ( ) : boolean {
416416 const { type, session } = getSession ( {
417- expiry,
417+ expiry : this . timeouts . sessionIdle ,
418+ maxSessionLife : this . timeouts . maxSessionLife ,
418419 stickySession : Boolean ( this . _options . stickySession ) ,
419420 currentSession : this . session ,
420421 sessionSampleRate : this . _options . sessionSampleRate ,
@@ -626,7 +627,7 @@ export class ReplayContainer implements ReplayContainerInterface {
626627 return ;
627628 }
628629
629- const expired = isSessionExpired ( this . session , VISIBILITY_CHANGE_TIMEOUT ) ;
630+ const expired = isSessionExpired ( this . session , this . timeouts . maxSessionLife , this . timeouts . sessionIdle ) ;
630631
631632 if ( breadcrumb && ! expired ) {
632633 this . _createCustomBreadcrumb ( breadcrumb ) ;
@@ -646,10 +647,10 @@ export class ReplayContainer implements ReplayContainerInterface {
646647 return ;
647648 }
648649
649- const isSessionActive = this . checkAndHandleExpiredSession ( VISIBILITY_CHANGE_TIMEOUT ) ;
650+ const isSessionActive = this . checkAndHandleExpiredSession ( ) ;
650651
651652 if ( ! isSessionActive ) {
652- // If the user has come back to the page within VISIBILITY_CHANGE_TIMEOUT
653+ // If the user has come back to the page within SESSION_IDLE_DURATION
653654 // ms, we will re-use the existing session, otherwise create a new
654655 // session
655656 __DEBUG_BUILD__ && logger . log ( '[Replay] Document has become active, but session has expired' ) ;
0 commit comments