Skip to content

Commit 6887454

Browse files
committed
small fixes
1 parent d35aa65 commit 6887454

File tree

3 files changed

+32
-4
lines changed

3 files changed

+32
-4
lines changed

packages/replay/src/replay.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff 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,

packages/replay/src/util/sampleSession.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,5 @@ export function sampleSession({
1919
return 'session';
2020
}
2121

22-
return 'buffer';
22+
return errorSampleRate > 0 ? 'buffer' : false;
2323
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
});

0 commit comments

Comments
 (0)