-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(replay): Fix user activity not being updated in
start()
(#12001)
Replays will fail to start recording when using `start()` specifically when manually recording and after the user has been idle for a long period of time. We need to reset the user activity state when we call `start()`, otherwise the session will be [incorrectly] considered to be idle and unable to send any replay events. Closes #11983
- Loading branch information
Showing
2 changed files
with
59 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { vi } from 'vitest'; | ||
|
||
import { getClient } from '@sentry/core'; | ||
import type { Transport } from '@sentry/types'; | ||
|
||
import { DEFAULT_FLUSH_MIN_DELAY, SESSION_IDLE_EXPIRE_DURATION } from '../../src/constants'; | ||
import type { Replay } from '../../src/integration'; | ||
import type { ReplayContainer } from '../../src/replay'; | ||
import { BASE_TIMESTAMP } from '../index'; | ||
import { resetSdkMock } from '../mocks/resetSdkMock'; | ||
import { useFakeTimers } from '../utils/use-fake-timers'; | ||
|
||
useFakeTimers(); | ||
|
||
describe('Integration | start', () => { | ||
let replay: ReplayContainer; | ||
let integration: Replay; | ||
|
||
beforeEach(async () => { | ||
({ replay, integration } = await resetSdkMock({ | ||
replayOptions: { | ||
stickySession: false, | ||
}, | ||
sentryOptions: { | ||
replaysSessionSampleRate: 0.0, | ||
}, | ||
})); | ||
|
||
const mockTransport = getClient()?.getTransport()?.send as vi.MockedFunction<Transport['send']>; | ||
mockTransport?.mockClear(); | ||
await vi.runAllTimersAsync(); | ||
}); | ||
|
||
afterEach(async () => { | ||
integration.stop(); | ||
|
||
await vi.runAllTimersAsync(); | ||
vi.setSystemTime(new Date(BASE_TIMESTAMP)); | ||
}); | ||
|
||
it('sends replay when calling `start()` after [SESSION_IDLE_EXPIRE_DURATION]ms', async () => { | ||
await vi.advanceTimersByTimeAsync(SESSION_IDLE_EXPIRE_DURATION + 1); | ||
|
||
integration.start(); | ||
|
||
await vi.advanceTimersByTimeAsync(DEFAULT_FLUSH_MIN_DELAY); | ||
|
||
expect(replay).toHaveLastSentReplay({ | ||
recordingPayloadHeader: { segment_id: 0 }, | ||
}); | ||
}); | ||
}); |