Skip to content

Commit

Permalink
♻️ wire configuration and trackViews changes
Browse files Browse the repository at this point in the history
  • Loading branch information
bcaudan committed May 27, 2021
1 parent cc76616 commit c9aec32
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 9 deletions.
6 changes: 6 additions & 0 deletions packages/core/src/domain/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const DEFAULT_CONFIGURATION = {
sampleRate: 100,
silentMultipleInit: false,
trackInteractions: false,
trackViewsManually: false,

/**
* arbitrary value, byte precision not needed
Expand Down Expand Up @@ -50,6 +51,7 @@ export interface UserConfiguration {
enableExperimentalFeatures?: string[]
silentMultipleInit?: boolean
trackInteractions?: boolean
trackViewsManually?: boolean
proxyHost?: string
beforeSend?: (event: any) => void

Expand Down Expand Up @@ -131,6 +133,10 @@ export function buildConfiguration(userConfiguration: UserConfiguration, buildEn
configuration.trackInteractions = !!userConfiguration.trackInteractions
}

if ('trackViewsManually' in userConfiguration) {
configuration.trackViewsManually = !!userConfiguration.trackViewsManually
}

return configuration
}

Expand Down
2 changes: 1 addition & 1 deletion packages/rum-core/src/boot/rum.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ function startRum(
user: {},
})
)
const { stop: viewCollectionStop } = startViewCollection(lifeCycle, location)
const { stop: viewCollectionStop } = startViewCollection(lifeCycle, configuration, location)
return {
stop: () => {
rumEventCollectionStop()
Expand Down
2 changes: 1 addition & 1 deletion packages/rum-core/src/boot/rum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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')
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ describe('viewCollection', () => {
.withConfiguration({
isEnabled: () => true,
})
.beforeBuild(({ lifeCycle }) => {
startViewCollection(lifeCycle, location)
.beforeBuild(({ lifeCycle, configuration }) => {
startViewCollection(lifeCycle, configuration, location)
})
})

Expand Down
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down

0 comments on commit c9aec32

Please sign in to comment.