Skip to content

Commit 7adf5db

Browse files
mydeabillyvg
authored andcommitted
fix(replay): Ensure replay_id is not captured when session is expired (#9109)
Closes #9106
1 parent 0ce0110 commit 7adf5db

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

packages/replay/src/coreHandlers/handleGlobalEvent.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,12 @@ export function handleGlobalEventListener(
3535
return event;
3636
}
3737

38+
// Ensure we do not add replay_id if the session is expired
39+
const isSessionActive = replay.checkAndHandleExpiredSession();
40+
if (!isSessionActive) {
41+
return event;
42+
}
43+
3844
// Unless `captureExceptions` is enabled, we want to ignore errors coming from rrweb
3945
// As there can be a bunch of stuff going wrong in internals there, that we don't want to bubble up to users
4046
if (isRrwebError(event, hint) && !replay.getOptions()._experiments.captureExceptions) {

packages/replay/test/integration/coreHandlers/handleGlobalEvent.test.ts

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import type { Event } from '@sentry/types';
22

33
import type { Replay as ReplayIntegration } from '../../../src';
4-
import { REPLAY_EVENT_NAME } from '../../../src/constants';
4+
import { REPLAY_EVENT_NAME, SESSION_IDLE_EXPIRE_DURATION } from '../../../src/constants';
55
import { handleGlobalEventListener } from '../../../src/coreHandlers/handleGlobalEvent';
66
import type { ReplayContainer } from '../../../src/replay';
7+
import { makeSession } from '../../../src/session/Session';
78
import { Error } from '../../fixtures/error';
89
import { Transaction } from '../../fixtures/transaction';
910
import { resetSdkMock } from '../../mocks/resetSdkMock';
@@ -102,6 +103,32 @@ describe('Integration | coreHandlers | handleGlobalEvent', () => {
102103
);
103104
});
104105

106+
it('does not add replayId if replay session is expired', async () => {
107+
const transaction = Transaction();
108+
const error = Error();
109+
110+
const now = Date.now();
111+
112+
replay.session = makeSession({
113+
id: 'test-session-id',
114+
segmentId: 0,
115+
lastActivity: now - SESSION_IDLE_EXPIRE_DURATION - 1,
116+
started: now - SESSION_IDLE_EXPIRE_DURATION - 1,
117+
sampled: 'session',
118+
});
119+
120+
expect(handleGlobalEventListener(replay)(transaction, {})).toEqual(
121+
expect.objectContaining({
122+
tags: expect.not.objectContaining({ replayId: expect.anything() }),
123+
}),
124+
);
125+
expect(handleGlobalEventListener(replay)(error, {})).toEqual(
126+
expect.objectContaining({
127+
tags: expect.not.objectContaining({ replayId: expect.anything() }),
128+
}),
129+
);
130+
});
131+
105132
it('tags errors and transactions with replay id for session samples', async () => {
106133
let integration: ReplayIntegration;
107134
({ replay, integration } = await resetSdkMock({}));

0 commit comments

Comments
 (0)