Skip to content

Commit

Permalink
fix(replay): Remove replay id from DSC on expired sessions (#14342)
Browse files Browse the repository at this point in the history
  • Loading branch information
chargome authored Nov 19, 2024
1 parent fe1fb8c commit da5b2e0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
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);
});
});

0 comments on commit da5b2e0

Please sign in to comment.