Skip to content

Commit 59a516b

Browse files
billyvgclaude
andcommitted
test(replay): Add test for replay_id on DSC after buffer-to-session conversion
Verifies that a cached DSC on the scope gets replay_id set after sendBufferedReplayOrFlush converts from buffer to session mode. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 30136ef commit 59a516b

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

packages/replay-internal/test/integration/errorSampleRate.test.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
*/
44

55
import '../utils/mock-internal-setTimeout';
6-
import { captureException, getClient } from '@sentry/core';
6+
import { captureException, getClient, getCurrentScope } from '@sentry/core';
77
import type { MockInstance } from 'vitest';
88
import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest';
99
import {
@@ -383,6 +383,28 @@ describe('Integration | errorSampleRate', () => {
383383
});
384384
});
385385

386+
it('sets replay_id on DSC after converting from buffer to session mode', async () => {
387+
const TEST_EVENT = getTestEventIncremental({ timestamp: BASE_TIMESTAMP });
388+
mockRecord._emitter(TEST_EVENT);
389+
390+
// Simulate a cached DSC on the scope (as browserTracingIntegration would set)
391+
getCurrentScope().setPropagationContext({
392+
traceId: '00000000000000000000000000000000',
393+
sampleRand: 0,
394+
dsc: { trace_id: '00000000000000000000000000000000', sampled: 'true' },
395+
});
396+
397+
expect(replay.recordingMode).toBe('buffer');
398+
const dsc = getCurrentScope().getPropagationContext().dsc!;
399+
expect(dsc.replay_id).toBeUndefined();
400+
401+
await replay.sendBufferedReplayOrFlush({ continueRecording: true });
402+
await vi.advanceTimersToNextTimerAsync();
403+
404+
expect(replay.recordingMode).toBe('session');
405+
expect(dsc.replay_id).toBe(replay.getSessionId());
406+
});
407+
386408
// This tests a regression where we were calling flush indiscriminantly in `stop()`
387409
it('does not upload a replay event if error is not sampled', async () => {
388410
// We are trying to replicate the case where error rate is 0 and session

0 commit comments

Comments
 (0)