Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import type { ReplayContainer } from '../types';
import { isErrorEvent, isFeedbackEvent, isReplayEvent, isTransactionEvent } from '../util/eventUtils';
import { isRrwebError } from '../util/isRrwebError';
import { logger } from '../util/logger';
import { resetReplayIdOnDynamicSamplingContext } from '../util/resetReplayIdOnDynamicSamplingContext';
import { addFeedbackBreadcrumb } from './util/addFeedbackBreadcrumb';
import { shouldSampleForBufferEvent } from './util/shouldSampleForBufferEvent';

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { REPLAY_EVENT_NAME, SESSION_IDLE_EXPIRE_DURATION } from '../../../src/co
import { handleGlobalEventListener } from '../../../src/coreHandlers/handleGlobalEvent';
import type { ReplayContainer } from '../../../src/replay';
import { makeSession } from '../../../src/session/Session';
import * as resetReplayIdOnDynamicSamplingContextModule from '../../../src/util/resetReplayIdOnDynamicSamplingContext';
import { Error } from '../../fixtures/error';
import { Transaction } from '../../fixtures/transaction';
import { resetSdkMock } from '../../mocks/resetSdkMock';
Expand Down Expand Up @@ -416,4 +417,21 @@ describe('Integration | coreHandlers | handleGlobalEvent', () => {
}),
);
});

it('resets replayId on DSC when session expires', () => {
const errorEvent = Error();
const txEvent = Transaction();

vi.spyOn(replay, 'checkAndHandleExpiredSession').mockReturnValue(false);

const resetReplayIdSpy = vi.spyOn(
resetReplayIdOnDynamicSamplingContextModule,
'resetReplayIdOnDynamicSamplingContext',
);

handleGlobalEventListener(replay)(errorEvent, {});
handleGlobalEventListener(replay)(txEvent, {});

expect(resetReplayIdSpy).toHaveBeenCalledTimes(2);
});
});
Loading