diff --git a/packages/browser-rum-core/src/domain/configuration/configuration.spec.ts b/packages/browser-rum-core/src/domain/configuration/configuration.spec.ts index 3eb13b6235..8f6ec47ffa 100644 --- a/packages/browser-rum-core/src/domain/configuration/configuration.spec.ts +++ b/packages/browser-rum-core/src/domain/configuration/configuration.spec.ts @@ -486,6 +486,53 @@ describe('validateAndBuildRumConfiguration', () => { }) }) + describe('betaEnableViewUpdates', () => { + // Unit tests are bundled as a CDN build (webpack.base.ts pins `setup: 'cdn'`), so the npm + // side of the default is only covered by e2e and by reading the code. + + it('defaults to true on a CDN build without a proxy', () => { + expect(validateAndBuildRumConfiguration(DEFAULT_INIT_CONFIGURATION)!.betaEnableViewUpdates).toBeTrue() + }) + + it('defaults to false on a CDN build with a proxy', () => { + expect( + validateAndBuildRumConfiguration({ ...DEFAULT_INIT_CONFIGURATION, proxy: 'https://proxy.example.com' })! + .betaEnableViewUpdates + ).toBeFalse() + }) + + it('defaults to false on a CDN build with a proxy function', () => { + expect( + validateAndBuildRumConfiguration({ ...DEFAULT_INIT_CONFIGURATION, proxy: () => 'https://proxy.example.com' })! + .betaEnableViewUpdates + ).toBeFalse() + }) + + it('honors an explicit false on a CDN build without a proxy', () => { + expect( + validateAndBuildRumConfiguration({ ...DEFAULT_INIT_CONFIGURATION, betaEnableViewUpdates: false })! + .betaEnableViewUpdates + ).toBeFalse() + }) + + it('honors an explicit true on a CDN build with a proxy', () => { + expect( + validateAndBuildRumConfiguration({ + ...DEFAULT_INIT_CONFIGURATION, + betaEnableViewUpdates: true, + proxy: 'https://proxy.example.com', + })!.betaEnableViewUpdates + ).toBeTrue() + }) + + it('does not validate the configuration if it is not a boolean', () => { + expect( + validateAndBuildRumConfiguration({ ...DEFAULT_INIT_CONFIGURATION, betaEnableViewUpdates: 'yes' as any }) + ).toBeUndefined() + expect(displayErrorSpy).toHaveBeenCalledOnceWith('"betaEnableViewUpdates" must be a boolean') + }) + }) + describe('trackResourceHeaders', () => { describe('disabled', () => { it('defaults to empty array', () => { @@ -919,6 +966,26 @@ describe('validateAndBuildRumConfiguration', () => { }) describe('serializeRumConfiguration', () => { + describe('beta_enable_view_updates', () => { + it('reports the effective default on a CDN build without a proxy', () => { + expect(serializeRumConfiguration(DEFAULT_INIT_CONFIGURATION).beta_enable_view_updates).toBeTrue() + }) + + it('reports the effective default on a CDN build with a proxy', () => { + expect( + serializeRumConfiguration({ ...DEFAULT_INIT_CONFIGURATION, proxy: 'https://proxy.example.com' }) + .beta_enable_view_updates + ).toBeFalse() + }) + + it('reports an explicitly disabled option', () => { + expect( + serializeRumConfiguration({ ...DEFAULT_INIT_CONFIGURATION, betaEnableViewUpdates: false }) + .beta_enable_view_updates + ).toBeFalse() + }) + }) + it('should serialize the configuration', () => { const exhaustiveRumInitConfiguration: Required = { ...EXHAUSTIVE_INIT_CONFIGURATION, diff --git a/packages/browser-rum-core/src/domain/configuration/configuration.ts b/packages/browser-rum-core/src/domain/configuration/configuration.ts index 49999e317e..7f88a0de68 100644 --- a/packages/browser-rum-core/src/domain/configuration/configuration.ts +++ b/packages/browser-rum-core/src/domain/configuration/configuration.ts @@ -20,6 +20,9 @@ import type { RumPlugin } from '../plugins' import type { PropagatorType, TracingOption } from '../tracing/tracer.types' import { getRemoteConfigurationId } from './remoteConfiguration' +// replaced at build time +declare const __BUILD_ENV__SDK_SETUP__: string + export const DEFAULT_PROPAGATOR_TYPES: PropagatorType[] = ['tracecontext', 'datadog'] /** @@ -350,6 +353,9 @@ export interface RumInitConfiguration extends InitConfiguration { * Enable partial view updates, which reduces bandwidth by sending only changed * fields instead of full view events on intermediate updates. * + * Enabled by default when the SDK is loaded from the CDN and no `proxy` is configured. + * Disabled by default otherwise, because a proxy may not forward the `view_update` event type. + * * @category Beta */ betaEnableViewUpdates?: boolean | undefined @@ -413,7 +419,7 @@ export const RUM_SCHEMA = { trackResources: { type: 'boolean', default: true, strict: false }, trackLongTasks: { type: 'boolean', default: true, strict: false }, trackViewsManually: { type: 'boolean', default: false, strict: false }, - betaEnableViewUpdates: { type: 'boolean', default: false }, + betaEnableViewUpdates: { type: 'boolean' }, betaTrackWebSockets: { type: 'boolean', default: false, strict: false }, enablePrivacyForActionName: { type: 'boolean', default: true }, propagateTraceBaggage: { type: 'boolean', default: true }, @@ -491,12 +497,25 @@ export const RUM_SCHEMA = { export type RumConfiguration = Omit, 'allowedTracingUrls'> & { allowedTracingUrls: TracingOption[] + betaEnableViewUpdates: boolean rulePsr: number | undefined trackResourceHeaders: MatchHeader[] allowedGraphQlUrls: GraphQlUrlOption[] remoteConfigurationId: string | undefined } +/** + * Partial view updates are enabled by default for CDN users that do not go through a proxy: a + * proxy may not forward the `view_update` event type yet, and npm users pin an SDK version so + * they opt in explicitly. An explicit `betaEnableViewUpdates` always takes precedence. + * + * The CDN check is temporary, the next step is to default this to true unless `proxy` is set. + * TODO next major: remove the option. + */ +function isViewUpdatesEnabledByDefault(proxy: InitConfiguration['proxy']): boolean { + return __BUILD_ENV__SDK_SETUP__ === 'cdn' && !proxy +} + export function validateAndBuildRumConfiguration( initConfiguration: RumInitConfiguration ): RumConfiguration | undefined { @@ -524,6 +543,7 @@ export function validateAndBuildRumConfiguration( return { ...config, sessionReplayCanvasRecording, + betaEnableViewUpdates: config.betaEnableViewUpdates ?? isViewUpdatesEnabledByDefault(config.proxy), allowedTracingUrls, beforeSend: config.beforeSend ? (catchUserErrors(config.beforeSend, 'beforeSend threw an error:') as typeof config.beforeSend) @@ -718,7 +738,7 @@ export function serializeRumConfiguration(configuration: RumInitConfiguration) { profiling_sample_rate: configuration.profilingSampleRate, use_remote_configuration_proxy: !!configuration.remoteConfigurationProxy, track_resource_headers: getTrackResourceHeadersTelemetryValue(configuration.trackResourceHeaders), - beta_enable_view_updates: configuration.betaEnableViewUpdates, + beta_enable_view_updates: configuration.betaEnableViewUpdates ?? isViewUpdatesEnabledByDefault(configuration.proxy), beta_track_web_sockets: configuration.betaTrackWebSockets, ...baseSerializedConfiguration, } satisfies RawTelemetryConfiguration