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 @@ -398,7 +398,7 @@ export class ReplayContainer implements ReplayContainerInterface {
398398 this . recordingMode = 'session' ;
399399
400400 if ( this . session ) {
401- this . _updateSessionActivity ( activityTime ) ;
401+ this . session . lastActivity = activityTime ;
402402 this . session . started = activityTime ;
403403 this . _maybeSaveSession ( ) ;
404404 }
@@ -537,7 +537,7 @@ export class ReplayContainer implements ReplayContainerInterface {
537537
538538 /**
539539 * Check the state/expiration of the session.
540- * The callback is used when the session is neither paused nor expired.
540+ * The callback is called when the session is neither paused nor expired.
541541 */
542542 public checkSessionState ( onContinue : ( ) => void ) : void {
543543 if ( ! this . session || ! this . session . sampled ) {
@@ -608,7 +608,7 @@ export class ReplayContainer implements ReplayContainerInterface {
608608
609609 // this method is generally called on page load or manually - in both cases
610610 // we should treat it as an activity
611- this . _updateSessionActivity ( ) ;
611+ this . updateUserActivity ( ) ;
612612
613613 this . eventBuffer = createEventBuffer ( {
614614 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