|
1 | 1 | import { getCurrentHub } from '@sentry/core';
|
2 | 2 | import type { BrowserClientReplayOptions, Integration } from '@sentry/types';
|
3 |
| -import { dropUndefinedKeys } from '@sentry/utils'; |
| 3 | +import { dropUndefinedKeys, logger } from '@sentry/utils'; |
4 | 4 |
|
5 | 5 | import { DEFAULT_FLUSH_MAX_DELAY, DEFAULT_FLUSH_MIN_DELAY, MASK_ALL_TEXT_SELECTOR } from './constants';
|
6 | 6 | import { ReplayContainer } from './replay';
|
@@ -201,45 +201,47 @@ Sentry.init({ replaysOnErrorSampleRate: ${errorSampleRate} })`,
|
201 | 201 | /** Setup the integration. */
|
202 | 202 | private _setup(): void {
|
203 | 203 | // Client is not available in constructor, so we need to wait until setupOnce
|
204 |
| - const finalOptions = this._loadReplayOptionsFromClient(this._initialOptions); |
| 204 | + const finalOptions = loadReplayOptionsFromClient(this._initialOptions); |
205 | 205 |
|
206 | 206 | this._replay = new ReplayContainer({
|
207 | 207 | options: finalOptions,
|
208 | 208 | recordingOptions: this._recordingOptions,
|
209 | 209 | });
|
210 | 210 | }
|
| 211 | +} |
211 | 212 |
|
212 |
| - /** Parse Replay-related options from SDK options */ |
213 |
| - private _loadReplayOptionsFromClient(initialOptions: InitialReplayPluginOptions): ReplayPluginOptions { |
214 |
| - const client = getCurrentHub().getClient(); |
215 |
| - const opt = client && (client.getOptions() as BrowserClientReplayOptions | undefined); |
216 |
| - |
217 |
| - const finalOptions = { sessionSampleRate: 0, errorSampleRate: 0, ...dropUndefinedKeys(initialOptions) }; |
| 213 | +/** Parse Replay-related options from SDK options */ |
| 214 | +function loadReplayOptionsFromClient(initialOptions: InitialReplayPluginOptions): ReplayPluginOptions { |
| 215 | + const client = getCurrentHub().getClient(); |
| 216 | + const opt = client && (client.getOptions() as BrowserClientReplayOptions); |
218 | 217 |
|
219 |
| - if (!opt) { |
220 |
| - return finalOptions; |
221 |
| - } |
| 218 | + const finalOptions = { sessionSampleRate: 0, errorSampleRate: 0, ...dropUndefinedKeys(initialOptions) }; |
222 | 219 |
|
223 |
| - if ( |
224 |
| - initialOptions.sessionSampleRate == null && // TODO remove once deprecated rates are removed |
225 |
| - initialOptions.errorSampleRate == null && // TODO remove once deprecated rates are removed |
226 |
| - opt.replaysSessionSampleRate == null && |
227 |
| - opt.replaysOnErrorSampleRate == null |
228 |
| - ) { |
229 |
| - // eslint-disable-next-line no-console |
230 |
| - console.warn( |
231 |
| - 'Replay is disabled because neither `replaysSessionSampleRate` nor `replaysOnErrorSampleRate` are set', |
232 |
| - ); |
233 |
| - } |
| 220 | + if (!opt) { |
| 221 | + // eslint-disable-next-line no-console |
| 222 | + console.warn('Replay is disabled because SDK options are not available'); |
| 223 | + return finalOptions; |
| 224 | + } |
234 | 225 |
|
235 |
| - if (typeof opt.replaysSessionSampleRate === 'number') { |
236 |
| - finalOptions.sessionSampleRate = opt.replaysSessionSampleRate; |
237 |
| - } |
| 226 | + if ( |
| 227 | + initialOptions.sessionSampleRate == null && // TODO remove once deprecated rates are removed |
| 228 | + initialOptions.errorSampleRate == null && // TODO remove once deprecated rates are removed |
| 229 | + opt.replaysSessionSampleRate == null && |
| 230 | + opt.replaysOnErrorSampleRate == null |
| 231 | + ) { |
| 232 | + // eslint-disable-next-line no-console |
| 233 | + console.warn( |
| 234 | + 'Replay is disabled because neither `replaysSessionSampleRate` nor `replaysOnErrorSampleRate` are set.', |
| 235 | + ); |
| 236 | + } |
238 | 237 |
|
239 |
| - if (typeof opt.replaysOnErrorSampleRate === 'number') { |
240 |
| - finalOptions.errorSampleRate = opt.replaysOnErrorSampleRate; |
241 |
| - } |
| 238 | + if (typeof opt.replaysSessionSampleRate === 'number') { |
| 239 | + finalOptions.sessionSampleRate = opt.replaysSessionSampleRate; |
| 240 | + } |
242 | 241 |
|
243 |
| - return finalOptions; |
| 242 | + if (typeof opt.replaysOnErrorSampleRate === 'number') { |
| 243 | + finalOptions.errorSampleRate = opt.replaysOnErrorSampleRate; |
244 | 244 | }
|
| 245 | + |
| 246 | + return finalOptions; |
245 | 247 | }
|
0 commit comments