From c9aec323a51824c40940562a77f30e5849465a18 Mon Sep 17 00:00:00 2001 From: Bastien Caudan Date: Thu, 27 May 2021 12:16:55 +0200 Subject: [PATCH] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20wire=20configuration=20and?= =?UTF-8?q?=20trackViews=20changes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/domain/configuration.ts | 6 ++++++ packages/rum-core/src/boot/rum.spec.ts | 2 +- packages/rum-core/src/boot/rum.ts | 2 +- .../view/trackLocationChanges.spec.ts | 2 +- .../view/trackViewMetrics.spec.ts | 2 +- .../view/viewCollection.spec.ts | 4 ++-- .../rumEventsCollection/view/viewCollection.ts | 14 +++++++++++--- 7 files changed, 23 insertions(+), 9 deletions(-) diff --git a/packages/core/src/domain/configuration.ts b/packages/core/src/domain/configuration.ts index c79de5f8d8..aba52a73a0 100644 --- a/packages/core/src/domain/configuration.ts +++ b/packages/core/src/domain/configuration.ts @@ -12,6 +12,7 @@ export const DEFAULT_CONFIGURATION = { sampleRate: 100, silentMultipleInit: false, trackInteractions: false, + trackViewsManually: false, /** * arbitrary value, byte precision not needed @@ -50,6 +51,7 @@ export interface UserConfiguration { enableExperimentalFeatures?: string[] silentMultipleInit?: boolean trackInteractions?: boolean + trackViewsManually?: boolean proxyHost?: string beforeSend?: (event: any) => void @@ -131,6 +133,10 @@ export function buildConfiguration(userConfiguration: UserConfiguration, buildEn configuration.trackInteractions = !!userConfiguration.trackInteractions } + if ('trackViewsManually' in userConfiguration) { + configuration.trackViewsManually = !!userConfiguration.trackViewsManually + } + return configuration } diff --git a/packages/rum-core/src/boot/rum.spec.ts b/packages/rum-core/src/boot/rum.spec.ts index 2ca17fcb92..46f9cb41e5 100644 --- a/packages/rum-core/src/boot/rum.spec.ts +++ b/packages/rum-core/src/boot/rum.spec.ts @@ -35,7 +35,7 @@ function startRum( user: {}, }) ) - const { stop: viewCollectionStop } = startViewCollection(lifeCycle, location) + const { stop: viewCollectionStop } = startViewCollection(lifeCycle, configuration, location) return { stop: () => { rumEventCollectionStop() diff --git a/packages/rum-core/src/boot/rum.ts b/packages/rum-core/src/boot/rum.ts index 7c22cd9175..0faa0e32a7 100644 --- a/packages/rum-core/src/boot/rum.ts +++ b/packages/rum-core/src/boot/rum.ts @@ -44,7 +44,7 @@ export function startRum(userConfiguration: RumUserConfiguration, getCommonConte startLongTaskCollection(lifeCycle) startResourceCollection(lifeCycle, session) - const { addTiming, startView } = startViewCollection(lifeCycle, location) + const { addTiming, startView } = startViewCollection(lifeCycle, configuration, location) const { addError } = startErrorCollection(lifeCycle, configuration) const { addAction } = startActionCollection(lifeCycle, configuration) diff --git a/packages/rum-core/src/domain/rumEventsCollection/view/trackLocationChanges.spec.ts b/packages/rum-core/src/domain/rumEventsCollection/view/trackLocationChanges.spec.ts index 7c453b4566..a7e61bb0bd 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/view/trackLocationChanges.spec.ts +++ b/packages/rum-core/src/domain/rumEventsCollection/view/trackLocationChanges.spec.ts @@ -20,7 +20,7 @@ describe('rum track location change', () => { initialViewId = id subscription.unsubscribe() }) - return trackViews(location, lifeCycle) + return trackViews(location, lifeCycle, true) }) createSpy = jasmine.createSpy('create') }) diff --git a/packages/rum-core/src/domain/rumEventsCollection/view/trackViewMetrics.spec.ts b/packages/rum-core/src/domain/rumEventsCollection/view/trackViewMetrics.spec.ts index 5f4715df81..4e150ca8b8 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/view/trackViewMetrics.spec.ts +++ b/packages/rum-core/src/domain/rumEventsCollection/view/trackViewMetrics.spec.ts @@ -67,7 +67,7 @@ describe('rum track view metrics', () => { .withFakeLocation('/foo') .beforeBuild(({ location, lifeCycle }) => { lifeCycle.subscribe(LifeCycleEventType.VIEW_UPDATED, handler) - return trackViews(location, lifeCycle) + return trackViews(location, lifeCycle, true) }) }) diff --git a/packages/rum-core/src/domain/rumEventsCollection/view/viewCollection.spec.ts b/packages/rum-core/src/domain/rumEventsCollection/view/viewCollection.spec.ts index 88fe032837..775836cf6d 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/view/viewCollection.spec.ts +++ b/packages/rum-core/src/domain/rumEventsCollection/view/viewCollection.spec.ts @@ -13,8 +13,8 @@ describe('viewCollection', () => { .withConfiguration({ isEnabled: () => true, }) - .beforeBuild(({ lifeCycle }) => { - startViewCollection(lifeCycle, location) + .beforeBuild(({ lifeCycle, configuration }) => { + startViewCollection(lifeCycle, configuration, location) }) }) diff --git a/packages/rum-core/src/domain/rumEventsCollection/view/viewCollection.ts b/packages/rum-core/src/domain/rumEventsCollection/view/viewCollection.ts index 1a6e4aecea..f6c05c8f48 100644 --- a/packages/rum-core/src/domain/rumEventsCollection/view/viewCollection.ts +++ b/packages/rum-core/src/domain/rumEventsCollection/view/viewCollection.ts @@ -1,14 +1,22 @@ -import { Duration, isEmptyObject, mapValues, ServerDuration, toServerDuration } from '@datadog/browser-core' +import { + Duration, + isEmptyObject, + mapValues, + ServerDuration, + toServerDuration, + Configuration, +} from '@datadog/browser-core' import { RawRumViewEvent, RumEventType } from '../../../rawRumEvent.types' import { LifeCycle, LifeCycleEventType } from '../../lifeCycle' import { trackViews, ViewEvent } from './trackViews' -export function startViewCollection(lifeCycle: LifeCycle, location: Location) { +export function startViewCollection(lifeCycle: LifeCycle, configuration: Configuration, location: Location) { lifeCycle.subscribe(LifeCycleEventType.VIEW_UPDATED, (view) => lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, processViewUpdate(view)) ) - return trackViews(location, lifeCycle) + const shouldTrackViewsAutomatically = !configuration.isEnabled('view-renaming') || !configuration.trackViewsManually + return trackViews(location, lifeCycle, shouldTrackViewsAutomatically) } function processViewUpdate(view: ViewEvent) {