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 {
398
398
this . recordingMode = 'session' ;
399
399
400
400
if ( this . session ) {
401
- this . _updateSessionActivity ( activityTime ) ;
401
+ this . session . lastActivity = activityTime ;
402
402
this . session . started = activityTime ;
403
403
this . _maybeSaveSession ( ) ;
404
404
}
@@ -537,7 +537,7 @@ export class ReplayContainer implements ReplayContainerInterface {
537
537
538
538
/**
539
539
* 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.
541
541
*/
542
542
public checkSessionState ( onContinue : ( ) => void ) : void {
543
543
if ( ! this . session || ! this . session . sampled ) {
@@ -608,7 +608,7 @@ export class ReplayContainer implements ReplayContainerInterface {
608
608
609
609
// this method is generally called on page load or manually - in both cases
610
610
// we should treat it as an activity
611
- this . _updateSessionActivity ( ) ;
611
+ this . updateUserActivity ( ) ;
612
612
613
613
this . eventBuffer = createEventBuffer ( {
614
614
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