Skip to content

Commit 1bc1fbf

Browse files
👌 Make canvas recording configuration extensible
1 parent 98910e4 commit 1bc1fbf

2 files changed

Lines changed: 41 additions & 38 deletions

File tree

‎packages/browser-rum-core/src/domain/configuration/configuration.spec.ts‎

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -332,18 +332,16 @@ describe('validateAndBuildRumConfiguration', () => {
332332
it('is disabled by default', () => {
333333
const configuration = validateAndBuildRumConfiguration(DEFAULT_INIT_CONFIGURATION)!
334334

335-
expect(configuration.enableSessionReplayCanvasRecording).toBeFalse()
336-
expect(configuration.sessionReplayMaxCanvasFps).toBe(0)
335+
expect(configuration.enableSessionReplayCanvasRecording).toBeUndefined()
337336
})
338337

339338
it('stays disabled when requested without the experimental feature', () => {
340339
const configuration = validateAndBuildRumConfiguration({
341340
...DEFAULT_INIT_CONFIGURATION,
342-
enableSessionReplayCanvasRecording: true,
341+
enableSessionReplayCanvasRecording: {},
343342
})!
344343

345-
expect(configuration.enableSessionReplayCanvasRecording).toBeFalse()
346-
expect(configuration.sessionReplayMaxCanvasFps).toBe(0)
344+
expect(configuration.enableSessionReplayCanvasRecording).toBeUndefined()
347345
})
348346

349347
describe('when the experimental feature is enabled', () => {
@@ -354,21 +352,29 @@ describe('validateAndBuildRumConfiguration', () => {
354352
it('uses one frame per second by default when enabled', () => {
355353
const configuration = validateAndBuildRumConfiguration({
356354
...DEFAULT_INIT_CONFIGURATION,
357-
enableSessionReplayCanvasRecording: true,
355+
enableSessionReplayCanvasRecording: {},
358356
})!
359357

360-
expect(configuration.enableSessionReplayCanvasRecording).toBeTrue()
361-
expect(configuration.sessionReplayMaxCanvasFps).toBe(1)
358+
expect(configuration.enableSessionReplayCanvasRecording).toEqual({ maxFramesPerSecond: 1 })
362359
})
363360

364361
it('uses the configured frame rate', () => {
365362
const configuration = validateAndBuildRumConfiguration({
366363
...DEFAULT_INIT_CONFIGURATION,
367-
enableSessionReplayCanvasRecording: true,
368-
sessionReplayMaxCanvasFps: 2.5,
364+
enableSessionReplayCanvasRecording: { maxFramesPerSecond: 2.5 },
369365
})!
370366

371-
expect(configuration.sessionReplayMaxCanvasFps).toBe(2.5)
367+
expect(configuration.enableSessionReplayCanvasRecording).toEqual({ maxFramesPerSecond: 2.5 })
368+
})
369+
370+
it('rejects invalid canvas recording options', () => {
371+
expect(
372+
validateAndBuildRumConfiguration({
373+
...DEFAULT_INIT_CONFIGURATION,
374+
enableSessionReplayCanvasRecording: true as any,
375+
})
376+
).toBeUndefined()
377+
expect(displayErrorSpy).toHaveBeenCalledOnceWith('"enableSessionReplayCanvasRecording" is not a valid object')
372378
})
373379
})
374380
})
@@ -923,8 +929,7 @@ describe('serializeRumConfiguration', () => {
923929
trackResourceHeaders: true,
924930
betaEnableViewUpdates: true,
925931
betaTrackWebSockets: false,
926-
enableSessionReplayCanvasRecording: true,
927-
sessionReplayMaxCanvasFps: 2.5,
932+
enableSessionReplayCanvasRecording: { maxFramesPerSecond: 2.5 },
928933
}
929934

930935
type MapRumInitConfigurationKey<Key extends string> = Key extends keyof InitConfiguration
@@ -940,12 +945,7 @@ describe('serializeRumConfiguration', () => {
940945
? 'track_long_task' // We forgot the s, keeping this for backward compatibility
941946
: // The following options are not reported as telemetry. Please avoid adding more of them.
942947
// `remoteConfiguration` is covered by the legacy `remote_configuration_id` field.
943-
Key extends
944-
| 'applicationId'
945-
| 'subdomain'
946-
| 'remoteConfiguration'
947-
| 'enableSessionReplayCanvasRecording'
948-
| 'sessionReplayMaxCanvasFps'
948+
Key extends 'applicationId' | 'subdomain' | 'remoteConfiguration' | 'enableSessionReplayCanvasRecording'
949949
? never
950950
: CamelToSnakeCase<Key>
951951
// By specifying the type here, we can ensure that serializeConfiguration is returning an

‎packages/browser-rum-core/src/domain/configuration/configuration.ts‎

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -214,23 +214,21 @@ export interface RumInitConfiguration extends InitConfiguration {
214214
startSessionReplayRecordingManually?: boolean | undefined
215215

216216
/**
217-
* Enables recording canvas elements in Session Replay.
217+
* Configures recording canvas elements in Session Replay. Canvas recording is disabled when this option is omitted.
218218
*
219219
* @category Session Replay
220-
* @defaultValue false
221-
* @hidden
222-
*/
223-
enableSessionReplayCanvasRecording?: boolean | undefined
224-
225-
/**
226-
* The maximum number of canvas frames recorded per second. Setting this option to `0` disables canvas frame recording.
227-
* This option has no effect unless {@link RumInitConfiguration.enableSessionReplayCanvasRecording | enableSessionReplayCanvasRecording} is enabled.
228-
*
229-
* @category Session Replay
230-
* @defaultValue 1
231220
* @hidden
232221
*/
233-
sessionReplayMaxCanvasFps?: number | undefined
222+
enableSessionReplayCanvasRecording?:
223+
| {
224+
/**
225+
* The maximum number of canvas frames recorded per second. Setting this option to `0` disables canvas frame recording.
226+
*
227+
* @defaultValue 1
228+
*/
229+
maxFramesPerSecond?: number | undefined
230+
}
231+
| undefined
234232

235233
/**
236234
* Enables privacy control for action names.
@@ -415,8 +413,12 @@ export const RUM_SCHEMA = {
415413
enablePrivacyForActionName: { type: 'boolean', default: true },
416414
propagateTraceBaggage: { type: 'boolean', default: true },
417415
startSessionReplayRecordingManually: { type: 'boolean', default: false, strict: false },
418-
enableSessionReplayCanvasRecording: { type: 'boolean', default: false },
419-
sessionReplayMaxCanvasFps: { type: 'number', min: 0, max: 5, default: 1 },
416+
enableSessionReplayCanvasRecording: {
417+
type: 'schema',
418+
schema: {
419+
maxFramesPerSecond: { type: 'number', min: 0, max: 5, default: 1 },
420+
},
421+
},
420422

421423
// Enums
422424
defaultPrivacyLevel: {
@@ -509,14 +511,15 @@ export function validateAndBuildRumConfiguration(
509511
return
510512
}
511513

512-
const enableSessionReplayCanvasRecording =
513-
config.enableSessionReplayCanvasRecording &&
514-
isExperimentalFeatureEnabled(ExperimentalFeature.SESSION_REPLAY_RECORD_CANVAS)
514+
const enableSessionReplayCanvasRecording = isExperimentalFeatureEnabled(
515+
ExperimentalFeature.SESSION_REPLAY_RECORD_CANVAS
516+
)
517+
? config.enableSessionReplayCanvasRecording
518+
: undefined
515519

516520
return {
517521
...config,
518522
enableSessionReplayCanvasRecording,
519-
sessionReplayMaxCanvasFps: enableSessionReplayCanvasRecording ? config.sessionReplayMaxCanvasFps : 0,
520523
allowedTracingUrls,
521524
beforeSend: config.beforeSend
522525
? (catchUserErrors(config.beforeSend, 'beforeSend threw an error:') as typeof config.beforeSend)

0 commit comments

Comments
 (0)