Skip to content

Commit

Permalink
Set service and version in startViews
Browse files Browse the repository at this point in the history
  • Loading branch information
amortemousque committed Jan 23, 2025
1 parent b7d8fb0 commit 02f9fb2
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 20 deletions.
12 changes: 0 additions & 12 deletions packages/rum-core/src/domain/assembly.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,18 +535,6 @@ describe('rum assembly', () => {
describe('service and version', () => {
const extraConfigurationOptions = { service: 'default service', version: 'default version' }

it('should come from the init configuration by default', () => {
const { lifeCycle, serverRumEvents } = setupAssemblyTestWithDefaults({
partialConfiguration: extraConfigurationOptions,
})

notifyRawRumEvent(lifeCycle, {
rawRumEvent: createRawRumEvent(RumEventType.ACTION),
})
expect(serverRumEvents[0].service).toEqual('default service')
expect(serverRumEvents[0].version).toEqual('default version')
})

describe('fields service and version', () => {
it('it should be modifiable', () => {
const { lifeCycle, serverRumEvents } = setupAssemblyTestWithDefaults({
Expand Down
2 changes: 0 additions & 2 deletions packages/rum-core/src/domain/assembly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,6 @@ export function startRumAssembly(
id: configuration.applicationId,
},
date: timeStampNow(),
service: configuration.service,
version: configuration.version,
source: 'browser',
session: {
id: session.id,
Expand Down
9 changes: 7 additions & 2 deletions packages/rum-core/src/domain/view/setupViewTest.specHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Observable, deepClone } from '@datadog/browser-core'
import { mockRumConfiguration, setupLocationObserver } from '../../../test'
import type { LifeCycle } from '../lifeCycle'
import { LifeCycleEventType } from '../lifeCycle'
import type { RumConfiguration } from '../configuration'
import type { ViewCreatedEvent, ViewEvent, ViewOptions, ViewEndedEvent } from './trackViews'
import { trackViews } from './trackViews'

Expand All @@ -10,12 +11,16 @@ export type ViewTest = ReturnType<typeof setupViewTest>
interface ViewTrackingContext {
lifeCycle: LifeCycle
initialLocation?: string
partialConfig?: Partial<RumConfiguration>
}

export function setupViewTest({ lifeCycle, initialLocation }: ViewTrackingContext, initialViewOptions?: ViewOptions) {
export function setupViewTest(
{ lifeCycle, initialLocation, partialConfig }: ViewTrackingContext,
initialViewOptions?: ViewOptions
) {
const domMutationObservable = new Observable<void>()
const windowOpenObservable = new Observable<void>()
const configuration = mockRumConfiguration()
const configuration = mockRumConfiguration(partialConfig)
const { locationChangeObservable, changeLocation } = setupLocationObserver(initialLocation)

const {
Expand Down
40 changes: 40 additions & 0 deletions packages/rum-core/src/domain/view/trackViews.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -966,3 +966,43 @@ describe('view event count', () => {
})
})
})

describe('service and version', () => {
const lifeCycle = new LifeCycle()
let clock: Clock
let viewTest: ViewTest

beforeEach(() => {
clock = mockClock()

registerCleanupTask(() => {
viewTest.stop()
clock.cleanup()
resetExperimentalFeatures()
})
})

it('should come from the init configuration by default', () => {
viewTest = setupViewTest({ lifeCycle, partialConfig: { service: 'service', version: 'version' } })

const { getViewUpdate } = viewTest

expect(getViewUpdate(0).service).toEqual('service')
expect(getViewUpdate(0).version).toEqual('version')
})

it('should come from the view option if defined', () => {
viewTest = setupViewTest(
{ lifeCycle, partialConfig: { service: 'service', version: 'version' } },
{
service: 'view service',
version: 'view version',
}
)

const { getViewUpdate } = viewTest

expect(getViewUpdate(0).service).toEqual('view service')
expect(getViewUpdate(0).version).toEqual('view version')
})
})
13 changes: 9 additions & 4 deletions packages/rum-core/src/domain/view/trackViews.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,14 +209,19 @@ function newView(

let sessionIsActive = true
let name: string | undefined
let service: string | undefined
let version: string | undefined
let service = configuration.service
let version = configuration.version
let context: Context | undefined

if (viewOptions) {
name = viewOptions.name
service = viewOptions.service || undefined
version = viewOptions.version || undefined
if (viewOptions.service) {
service = viewOptions.service
}
if (viewOptions.version) {
version = viewOptions.version
}

if (viewOptions.context) {
context = viewOptions.context
// use ContextManager to update the context so we always sanitize it
Expand Down

0 comments on commit 02f9fb2

Please sign in to comment.