|
3 | 3 | */ |
4 | 4 |
|
5 | 5 | import '../utils/mock-internal-setTimeout'; |
6 | | -import { captureException, getClient } from '@sentry/core'; |
| 6 | +import { captureException, getClient, getCurrentScope } from '@sentry/core'; |
7 | 7 | import type { MockInstance } from 'vitest'; |
8 | 8 | import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'; |
9 | 9 | import { |
@@ -383,6 +383,28 @@ describe('Integration | errorSampleRate', () => { |
383 | 383 | }); |
384 | 384 | }); |
385 | 385 |
|
| 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 | + |
386 | 408 | // This tests a regression where we were calling flush indiscriminantly in `stop()` |
387 | 409 | it('does not upload a replay event if error is not sampled', async () => { |
388 | 410 | // We are trying to replicate the case where error rate is 0 and session |
|
0 commit comments