Skip to content

Commit da5b2e0

Browse files
authored
fix(replay): Remove replay id from DSC on expired sessions (#14342)
1 parent fe1fb8c commit da5b2e0

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

packages/replay-internal/src/coreHandlers/handleGlobalEvent.ts

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { ReplayContainer } from '../types';
55
import { isErrorEvent, isFeedbackEvent, isReplayEvent, isTransactionEvent } from '../util/eventUtils';
66
import { isRrwebError } from '../util/isRrwebError';
77
import { logger } from '../util/logger';
8+
import { resetReplayIdOnDynamicSamplingContext } from '../util/resetReplayIdOnDynamicSamplingContext';
89
import { addFeedbackBreadcrumb } from './util/addFeedbackBreadcrumb';
910
import { shouldSampleForBufferEvent } from './util/shouldSampleForBufferEvent';
1011

@@ -34,6 +35,8 @@ export function handleGlobalEventListener(replay: ReplayContainer): (event: Even
3435
// Ensure we do not add replay_id if the session is expired
3536
const isSessionActive = replay.checkAndHandleExpiredSession();
3637
if (!isSessionActive) {
38+
// prevent exceeding replay durations by removing the expired replayId from the DSC
39+
resetReplayIdOnDynamicSamplingContext();
3740
return event;
3841
}
3942

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

+18
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { REPLAY_EVENT_NAME, SESSION_IDLE_EXPIRE_DURATION } from '../../../src/co
1111
import { handleGlobalEventListener } from '../../../src/coreHandlers/handleGlobalEvent';
1212
import type { ReplayContainer } from '../../../src/replay';
1313
import { makeSession } from '../../../src/session/Session';
14+
import * as resetReplayIdOnDynamicSamplingContextModule from '../../../src/util/resetReplayIdOnDynamicSamplingContext';
1415
import { Error } from '../../fixtures/error';
1516
import { Transaction } from '../../fixtures/transaction';
1617
import { resetSdkMock } from '../../mocks/resetSdkMock';
@@ -416,4 +417,21 @@ describe('Integration | coreHandlers | handleGlobalEvent', () => {
416417
}),
417418
);
418419
});
420+
421+
it('resets replayId on DSC when session expires', () => {
422+
const errorEvent = Error();
423+
const txEvent = Transaction();
424+
425+
vi.spyOn(replay, 'checkAndHandleExpiredSession').mockReturnValue(false);
426+
427+
const resetReplayIdSpy = vi.spyOn(
428+
resetReplayIdOnDynamicSamplingContextModule,
429+
'resetReplayIdOnDynamicSamplingContext',
430+
);
431+
432+
handleGlobalEventListener(replay)(errorEvent, {});
433+
handleGlobalEventListener(replay)(txEvent, {});
434+
435+
expect(resetReplayIdSpy).toHaveBeenCalledTimes(2);
436+
});
419437
});

0 commit comments

Comments
 (0)