File tree 3 files changed +32
-4
lines changed
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 {
400
400
this . recordingMode = 'session' ;
401
401
402
402
if ( this . session ) {
403
- this . _updateSessionActivity ( activityTime ) ;
403
+ this . session . lastActivity = activityTime ;
404
404
this . session . started = activityTime ;
405
405
this . _maybeSaveSession ( ) ;
406
406
}
@@ -539,7 +539,7 @@ export class ReplayContainer implements ReplayContainerInterface {
539
539
540
540
/**
541
541
* 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.
543
543
*/
544
544
public checkSessionState ( onContinue : ( ) => void ) : void {
545
545
if ( ! this . session || ! this . session . sampled ) {
@@ -610,7 +610,7 @@ export class ReplayContainer implements ReplayContainerInterface {
610
610
611
611
// this method is generally called on page load or manually - in both cases
612
612
// we should treat it as an activity
613
- this . _updateSessionActivity ( ) ;
613
+ this . updateUserActivity ( ) ;
614
614
615
615
this . eventBuffer = createEventBuffer ( {
616
616
useCompression : this . _options . useCompression ,
Original file line number Diff line number Diff line change @@ -19,5 +19,5 @@ export function sampleSession({
19
19
return 'session' ;
20
20
}
21
21
22
- return 'buffer' ;
22
+ return errorSampleRate > 0 ? 'buffer' : false ;
23
23
}
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