Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
24 changes: 23 additions & 1 deletion packages/replay-internal/src/integration.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { parseSampleRate } from '@sentry/core';
import type { BrowserClientReplayOptions, Client, Integration, IntegrationFn } from '@sentry/types';
import type {
BrowserClientReplayOptions,
Client,
Integration,
IntegrationFn,
ReplayRecordingMode,
} from '@sentry/types';
import { consoleSandbox, dropUndefinedKeys, isBrowser } from '@sentry/utils';

import {
Expand Down Expand Up @@ -297,6 +303,22 @@ export class Replay implements Integration {
return this._replay.getSessionId();
}

/**
* Get the current recording mode. This can be either `session` or `buffer`.
*
* `session`: Recording the whole session, sending it continuously
* `buffer`: Always keeping the last 60s of recording, requires:
* - having replaysOnErrorSampleRate > 0 to capture replay when an error occurs
* - or calling `flush()` to send the replay
*/
public getRecordingMode(): ReplayRecordingMode | undefined {
if (!this._replay || !this._replay.isEnabled()) {
return;
}

return this._replay.recordingMode;
}

/**
* Initializes replay.
*/
Expand Down
2 changes: 1 addition & 1 deletion packages/replay-internal/src/replay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class ReplayContainer implements ReplayContainerInterface {
public clickDetector: ClickDetector | undefined;

/**
* Recording can happen in one of three modes:
* Recording can happen in one of two modes:
* - session: Record the whole session, sending it continuously
* - buffer: Always keep the last 60s of recording, requires:
* - having replaysOnErrorSampleRate > 0 to capture replay when an error occurs
Expand Down
42 changes: 42 additions & 0 deletions packages/replay-internal/test/integration/recordingMode.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/**
* @vitest-environment jsdom
*/

import { beforeEach, describe, expect, test } from 'vitest';
import type { Replay } from '../../src/integration';
import type { ReplayContainer } from '../../src/replay';
import { resetSdkMock } from '../mocks/resetSdkMock';
import { useFakeTimers } from '../utils/use-fake-timers';

useFakeTimers();

describe('Integration | getRecordingMode()', () => {
let replay: ReplayContainer;
let integration: Replay;

beforeEach(async () => {
({ replay, integration } = await resetSdkMock({
replayOptions: {
stickySession: false,
},
sentryOptions: {
replaysSessionSampleRate: 1.0,
},
}));
});

test('returns "session" when session sampling is enabled', async () => {
expect(integration.getRecordingMode()).toBe('session');
});

test('returns "buffer" when buffering is enabled', async () => {
replay.stop();
replay.startBuffering();
expect(integration.getRecordingMode()).toBe('buffer');
});

test('returns undefined when replay is stopped', async () => {
replay.stop();
expect(integration.getRecordingMode()).toBeUndefined();
});
});
Loading