Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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: 24 additions & 0 deletions packages/rum-core/src/domain/configuration/configuration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,28 @@ describe('validateAndBuildRumConfiguration', () => {
})
})

describe('trackWebVitals', () => {
it('defaults to true', () => {
expect(validateAndBuildRumConfiguration(DEFAULT_INIT_CONFIGURATION)!.trackWebVitals).toBeTrue()
})

it('is set to provided value', () => {
expect(
validateAndBuildRumConfiguration({ ...DEFAULT_INIT_CONFIGURATION, trackWebVitals: true })!.trackWebVitals
).toBeTrue()
expect(
validateAndBuildRumConfiguration({ ...DEFAULT_INIT_CONFIGURATION, trackWebVitals: false })!.trackWebVitals
).toBeFalse()
})

it('the provided value is cast to boolean', () => {
expect(
validateAndBuildRumConfiguration({ ...DEFAULT_INIT_CONFIGURATION, trackWebVitals: 'foo' as any })!
.trackWebVitals
).toBeTrue()
})
})

describe('trackResources', () => {
it('defaults to true', () => {
expect(validateAndBuildRumConfiguration(DEFAULT_INIT_CONFIGURATION)!.trackResources).toBeTrue()
Expand Down Expand Up @@ -535,6 +557,7 @@ describe('serializeRumConfiguration', () => {
trackUserInteractions: true,
actionNameAttribute: 'test-id',
trackViewsManually: true,
trackWebVitals: true,
trackResources: true,
trackLongTasks: true,
remoteConfigurationId: '123',
Expand All @@ -556,6 +579,7 @@ describe('serializeRumConfiguration', () => {
| 'remoteConfigurationId'
| 'profilingSampleRate'
| 'propagateTraceBaggage'
| 'trackWebVitals'
? never
: CamelToSnakeCase<Key>
// By specifying the type here, we can ensure that serializeConfiguration is returning an
Expand Down
10 changes: 10 additions & 0 deletions packages/rum-core/src/domain/configuration/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@ export interface RumInitConfiguration extends InitConfiguration {
* Allows you to control RUM views creation. See [Override default RUM view names](https://docs.datadoghq.com/real_user_monitoring/browser/advanced_configuration/?tab=npm#override-default-rum-view-names) for further information.
*/
trackViewsManually?: boolean | undefined
/**
* Enables collection of Web Vitals / initial view metrics (FCP, LCP, FID, loading time) on the
* initial load view. Disable it for pages that are loaded in the background or pre-warmed (e.g. a
* hidden Electron window) where these metrics would be measured from an irrelevant navigation
* start and reported as abnormally large values.
* @default true
*/
trackWebVitals?: boolean | undefined
/**
* Enables collection of resource events.
* @default true
Expand Down Expand Up @@ -178,6 +186,7 @@ export interface RumConfiguration extends Configuration {
startSessionReplayRecordingManually: boolean
trackUserInteractions: boolean
trackViewsManually: boolean
trackWebVitals: boolean
trackResources: boolean
trackLongTasks: boolean
version?: string
Expand Down Expand Up @@ -248,6 +257,7 @@ export function validateAndBuildRumConfiguration(
compressIntakeRequests: !!initConfiguration.compressIntakeRequests,
trackUserInteractions: !!(initConfiguration.trackUserInteractions ?? true),
trackViewsManually: !!initConfiguration.trackViewsManually,
trackWebVitals: !!(initConfiguration.trackWebVitals ?? true),
trackResources: !!(initConfiguration.trackResources ?? true),
trackLongTasks: !!(initConfiguration.trackLongTasks ?? true),
subdomain: initConfiguration.subdomain,
Expand Down
15 changes: 15 additions & 0 deletions packages/rum-core/src/domain/view/trackViews.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -447,6 +447,21 @@ describe('view metrics', () => {
})

describe('initial view metrics', () => {
it('should not be collected when trackWebVitals is disabled', () => {
viewTest.stop()
viewTest = setupViewTest({ lifeCycle, partialConfig: { trackWebVitals: false } })

notifyPerformanceEntries([
createPerformanceEntry(RumPerformanceEntryType.PAINT),
createPerformanceEntry(RumPerformanceEntryType.NAVIGATION),
createPerformanceEntry(RumPerformanceEntryType.LARGEST_CONTENTFUL_PAINT),
])
clock.tick(THROTTLE_VIEW_UPDATE_PERIOD)

const { getViewUpdate, getViewUpdateCount } = viewTest
expect(getViewUpdate(getViewUpdateCount() - 1).initialViewMetrics).toEqual({})
})

it('updates should be throttled', () => {
const { getViewUpdateCount, getViewUpdate } = viewTest
expect(getViewUpdateCount()).toEqual(1)
Expand Down
2 changes: 1 addition & 1 deletion packages/rum-core/src/domain/view/trackViews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ function newView(
)

const { stop: stopInitialViewMetricsTracking, initialViewMetrics } =
loadingType === ViewLoadingType.INITIAL_LOAD
loadingType === ViewLoadingType.INITIAL_LOAD && configuration.trackWebVitals
? trackInitialViewMetrics(configuration, setLoadEvent, scheduleViewUpdate)
: { stop: noop, initialViewMetrics: {} as InitialViewMetrics }

Expand Down
Loading