Skip to content
Draft
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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<RumInitConfiguration> = {
...EXHAUSTIVE_INIT_CONFIGURATION,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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']

/**
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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' },

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed the default. With default: false you can't tell if the user passed false or didn't pass anything, both end up as false after validation. So the default is resolved in validateAndBuildRumConfiguration instead.

betaTrackWebSockets: { type: 'boolean', default: false, strict: false },
enablePrivacyForActionName: { type: 'boolean', default: true },
propagateTraceBaggage: { type: 'boolean', default: true },
Expand Down Expand Up @@ -491,12 +497,25 @@ export const RUM_SCHEMA = {

export type RumConfiguration = Omit<InferredConfig<typeof RUM_SCHEMA>, '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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
Loading