File tree Expand file tree Collapse file tree 3 files changed +32
-4
lines changed Expand file tree Collapse file tree 3 files changed +32
-4
lines changed Original file line number Diff line number Diff line change @@ -400,7 +400,7 @@ export class ReplayContainer implements ReplayContainerInterface {
400400 this . recordingMode = 'session' ;
401401
402402 if ( this . session ) {
403- this . _updateSessionActivity ( activityTime ) ;
403+ this . session . lastActivity = activityTime ;
404404 this . session . started = activityTime ;
405405 this . _maybeSaveSession ( ) ;
406406 }
@@ -539,7 +539,7 @@ export class ReplayContainer implements ReplayContainerInterface {
539539
540540 /**
541541 * Check the state/expiration of the session.
542- * The callback is used when the session is neither paused nor expired.
542+ * The callback is called when the session is neither paused nor expired.
543543 */
544544 public checkSessionState ( onContinue : ( ) => void ) : void {
545545 if ( ! this . session || ! this . session . sampled ) {
@@ -610,7 +610,7 @@ export class ReplayContainer implements ReplayContainerInterface {
610610
611611 // this method is generally called on page load or manually - in both cases
612612 // we should treat it as an activity
613- this . _updateSessionActivity ( ) ;
613+ this . updateUserActivity ( ) ;
614614
615615 this . eventBuffer = createEventBuffer ( {
616616 useCompression : this . _options . useCompression ,
Original file line number Diff line number Diff line change @@ -19,5 +19,5 @@ export function sampleSession({
1919 return 'session' ;
2020 }
2121
22- return 'buffer' ;
22+ return errorSampleRate > 0 ? 'buffer' : false ;
2323}
Original file line number Diff line number Diff line change 1+ import type { Sampled } from '../../../src/types' ;
2+ import { sampleSession } from '../../../src/util/sampleSession' ;
3+
4+ // Note: We "fix" Math.random() to always return 0.2
5+ const cases : [ number , number , Sampled ] [ ] = [
6+ [ 0 , 0 , false ] ,
7+ [ - 1 , - 1 , false ] ,
8+ [ 1 , 0 , 'session' ] ,
9+ [ 0 , 1 , 'buffer' ] ,
10+ [ 0.1 , 0.1 , 'buffer' ] ,
11+ [ 0.1 , 0 , false ] ,
12+ [ 0.3 , 0.1 , 'session' ] ,
13+ [ 0.3 , 0 , 'session' ] ,
14+ ] ;
15+
16+ describe ( 'Unit | util | sampleSession' , ( ) => {
17+ const mockRandom = jest . spyOn ( Math , 'random' ) ;
18+
19+ test . each ( cases ) (
20+ 'given sessionSampleRate=%p and errorSampleRate=%p, result should be %p' ,
21+ ( sessionSampleRate : number , errorSampleRate : number , expectedResult : Sampled ) => {
22+ mockRandom . mockImplementationOnce ( ( ) => 0.2 ) ;
23+
24+ const result = sampleSession ( { sessionSampleRate, errorSampleRate } ) ;
25+ expect ( result ) . toEqual ( expectedResult ) ;
26+ } ,
27+ ) ;
28+ } ) ;
You can’t perform that action at this time.
0 commit comments