Skip to content

Commit

Permalink
♻️ remove v2 references
Browse files Browse the repository at this point in the history
  • Loading branch information
bcaudan committed Nov 23, 2020
1 parent eddebd7 commit cf533ed
Show file tree
Hide file tree
Showing 28 changed files with 254 additions and 266 deletions.
2 changes: 1 addition & 1 deletion packages/rum/src/boot/rum.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ interface ServerRumEvent {

function collectServerEvents(lifeCycle: LifeCycle) {
const serverRumEvents: ServerRumEvent[] = []
lifeCycle.subscribe(LifeCycleEventType.RUM_EVENT_V2_COLLECTED, ({ serverRumEvent }) => {
lifeCycle.subscribe(LifeCycleEventType.RUM_EVENT_COLLECTED, ({ serverRumEvent }) => {
serverRumEvents.push(serverRumEvent as any)
})
return serverRumEvents
Expand Down
6 changes: 3 additions & 3 deletions packages/rum/src/boot/rum.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { combine, commonInit, Configuration, Context } from '@datadog/browser-core'
import { startDOMMutationCollection } from '../browser/domMutationCollection'
import { startPerformanceCollection } from '../browser/performanceCollection'
import { startRumAssemblyV2 } from '../domain/assemblyV2'
import { startRumAssembly } from '../domain/assembly'
import { startInternalContext } from '../domain/internalContext'
import { LifeCycle } from '../domain/lifeCycle'
import { startParentContexts } from '../domain/parentContexts'
Expand All @@ -28,7 +28,7 @@ export function startRum(userConfiguration: RumUserConfiguration, getGlobalConte
{
application_id: userConfiguration.applicationId,
},
parentContexts.findViewV2(),
parentContexts.findView(),
getGlobalContext()
)
})
Expand Down Expand Up @@ -65,7 +65,7 @@ export function startRumEventCollection(
) {
const parentContexts = startParentContexts(lifeCycle, session)
const batch = startRumBatch(configuration, lifeCycle)
startRumAssemblyV2(applicationId, configuration, lifeCycle, session, parentContexts, getGlobalContext)
startRumAssembly(applicationId, configuration, lifeCycle, session, parentContexts, getGlobalContext)
startLongTaskCollection(lifeCycle, configuration)
startResourceCollection(lifeCycle, configuration, session)
startViewCollection(lifeCycle, configuration, location)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Context } from '@datadog/browser-core'
import { createRawRumEvent } from '../../test/fixtures'
import { setup, TestSetupBuilder } from '../../test/specHelper'
import { RumEventType } from '../typesV2'
import { startRumAssemblyV2 } from './assemblyV2'
import { RumEventType } from '../types'
import { startRumAssembly } from './assembly'
import { LifeCycle, LifeCycleEventType } from './lifeCycle'

interface ServerRumEvents {
Expand Down Expand Up @@ -31,7 +31,7 @@ interface ServerRumEvents {
}
}

describe('rum assembly v2', () => {
describe('rum assembly', () => {
let setupBuilder: TestSetupBuilder
let lifeCycle: LifeCycle
let globalContext: Context
Expand All @@ -49,12 +49,12 @@ describe('rum assembly v2', () => {
isTrackedWithResource: () => true,
})
.withParentContexts({
findActionV2: () => ({
findAction: () => ({
action: {
id: '7890',
},
}),
findViewV2: () => ({
findView: () => ({
session: {
id: viewSessionId,
},
Expand All @@ -66,12 +66,12 @@ describe('rum assembly v2', () => {
}),
})
.beforeBuild(({ applicationId, configuration, lifeCycle: localLifeCycle, session, parentContexts }) => {
startRumAssemblyV2(applicationId, configuration, localLifeCycle, session, parentContexts, () => globalContext)
startRumAssembly(applicationId, configuration, localLifeCycle, session, parentContexts, () => globalContext)
})
;({ lifeCycle } = setupBuilder.build())

serverRumEvents = []
lifeCycle.subscribe(LifeCycleEventType.RUM_EVENT_V2_COLLECTED, ({ serverRumEvent }) =>
lifeCycle.subscribe(LifeCycleEventType.RUM_EVENT_COLLECTED, ({ serverRumEvent }) =>
serverRumEvents.push((serverRumEvent as unknown) as ServerRumEvents)
)
})
Expand All @@ -82,7 +82,7 @@ describe('rum assembly v2', () => {

describe('events', () => {
it('should have snake cased attributes', () => {
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, {
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {
rawRumEvent: createRawRumEvent(RumEventType.LONG_TASK, { longTask: { duration: 2 } }),
startTime: 0,
})
Expand All @@ -93,7 +93,7 @@ describe('rum assembly v2', () => {

describe('rum context', () => {
it('should be merged with event attributes', () => {
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, {
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {
rawRumEvent: createRawRumEvent(RumEventType.VIEW, undefined),
startTime: 0,
})
Expand All @@ -103,7 +103,7 @@ describe('rum assembly v2', () => {
})

it('should be snake cased', () => {
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, {
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {
rawRumEvent: createRawRumEvent(RumEventType.VIEW, undefined),
startTime: 0,
})
Expand All @@ -112,7 +112,7 @@ describe('rum assembly v2', () => {
})

it('should be overwritten by event attributes', () => {
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, {
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {
rawRumEvent: createRawRumEvent(RumEventType.VIEW, { date: 10 }),
startTime: 0,
})
Expand All @@ -124,7 +124,7 @@ describe('rum assembly v2', () => {
describe('rum global context', () => {
it('should be merged with event attributes', () => {
globalContext = { bar: 'foo' }
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, {
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {
rawRumEvent: createRawRumEvent(RumEventType.VIEW),
startTime: 0,
})
Expand All @@ -134,12 +134,12 @@ describe('rum assembly v2', () => {

it('should ignore subsequent context mutation', () => {
globalContext = { bar: 'foo' }
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, {
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {
rawRumEvent: createRawRumEvent(RumEventType.VIEW),
startTime: 0,
})
delete globalContext.bar
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, {
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {
rawRumEvent: createRawRumEvent(RumEventType.VIEW),
startTime: 0,
})
Expand All @@ -150,7 +150,7 @@ describe('rum assembly v2', () => {

it('should not be automatically snake cased', () => {
globalContext = { fooBar: 'foo' }
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, {
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {
rawRumEvent: createRawRumEvent(RumEventType.VIEW),
startTime: 0,
})
Expand All @@ -161,7 +161,7 @@ describe('rum assembly v2', () => {
it('should ignore the current global context when a saved global context is provided', () => {
globalContext = { replacedContext: 'b', addedContext: 'x' }

lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, {
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {
rawRumEvent: createRawRumEvent(RumEventType.VIEW),
savedGlobalContext: { replacedContext: 'a' },
startTime: 0,
Expand All @@ -174,7 +174,7 @@ describe('rum assembly v2', () => {

describe('customer context', () => {
it('should be merged with event attributes', () => {
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, {
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {
customerContext: { foo: 'bar' },
rawRumEvent: createRawRumEvent(RumEventType.VIEW),
startTime: 0,
Expand All @@ -184,7 +184,7 @@ describe('rum assembly v2', () => {
})

it('should not be automatically snake cased', () => {
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, {
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {
customerContext: { fooBar: 'foo' },
rawRumEvent: createRawRumEvent(RumEventType.VIEW),
startTime: 0,
Expand All @@ -197,22 +197,22 @@ describe('rum assembly v2', () => {
describe('action context', () => {
it('should be added on some event categories', () => {
;[RumEventType.RESOURCE, RumEventType.LONG_TASK, RumEventType.ERROR].forEach((category) => {
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, {
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {
rawRumEvent: createRawRumEvent(category),
startTime: 0,
})
expect(serverRumEvents[0].action).toEqual({ id: '7890' })
serverRumEvents = []
})

lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, {
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {
rawRumEvent: createRawRumEvent(RumEventType.VIEW),
startTime: 0,
})
expect(serverRumEvents[0].action).not.toBeDefined()
serverRumEvents = []

lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, {
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {
rawRumEvent: createRawRumEvent(RumEventType.ACTION),
startTime: 0,
})
Expand All @@ -223,7 +223,7 @@ describe('rum assembly v2', () => {

describe('view context', () => {
it('should be merged with event attributes', () => {
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, {
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {
rawRumEvent: createRawRumEvent(RumEventType.ACTION),
startTime: 0,
})
Expand All @@ -240,7 +240,7 @@ describe('rum assembly v2', () => {
it('when tracked, it should generate event', () => {
isTracked = true

lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, {
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {
rawRumEvent: createRawRumEvent(RumEventType.VIEW),
startTime: 0,
})
Expand All @@ -250,7 +250,7 @@ describe('rum assembly v2', () => {
it('when not tracked, it should not generate event', () => {
isTracked = false

lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, {
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {
rawRumEvent: createRawRumEvent(RumEventType.VIEW),
startTime: 0,
})
Expand All @@ -260,7 +260,7 @@ describe('rum assembly v2', () => {
it('when view context has session id, it should generate event', () => {
viewSessionId = '1234'

lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, {
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {
rawRumEvent: createRawRumEvent(RumEventType.VIEW),
startTime: 0,
})
Expand All @@ -270,7 +270,7 @@ describe('rum assembly v2', () => {
it('when view context has no session id, it should not generate event', () => {
viewSessionId = undefined

lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, {
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {
rawRumEvent: createRawRumEvent(RumEventType.VIEW),
startTime: 0,
})
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { combine, Configuration, Context, withSnakeCaseKeys } from '@datadog/browser-core'
import {
RawRumEventV2,
RumContextV2,
RumErrorEventV2,
RawRumEvent,
RumContext,
RumErrorEvent,
RumEventType,
RumLongTaskEventV2,
RumResourceEventV2,
} from '../typesV2'
RumLongTaskEvent,
RumResourceEvent,
} from '../types'
import { LifeCycle, LifeCycleEventType } from './lifeCycle'
import { ParentContexts } from './parentContexts'
import { RumSession } from './rumSession'
Expand All @@ -20,7 +20,7 @@ enum SessionType {
USER = 'user',
}

export function startRumAssemblyV2(
export function startRumAssembly(
applicationId: string,
configuration: Configuration,
lifeCycle: LifeCycle,
Expand All @@ -29,22 +29,22 @@ export function startRumAssemblyV2(
getGlobalContext: () => Context
) {
lifeCycle.subscribe(
LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED,
LifeCycleEventType.RAW_RUM_EVENT_COLLECTED,
({
startTime,
rawRumEvent,
savedGlobalContext,
customerContext,
}: {
startTime: number
rawRumEvent: RawRumEventV2
rawRumEvent: RawRumEvent
savedGlobalContext?: Context
customerContext?: Context
}) => {
const viewContext = parentContexts.findViewV2(startTime)
const viewContext = parentContexts.findView(startTime)
if (session.isTracked() && viewContext && viewContext.session.id) {
const actionContext = parentContexts.findActionV2(startTime)
const rumContext: RumContextV2 = {
const actionContext = parentContexts.findAction(startTime)
const rumContext: RumContext = {
_dd: {
formatVersion: 2,
},
Expand All @@ -64,15 +64,15 @@ export function startRumAssemblyV2(
: combine(rumContext, viewContext, rawRumEvent)
const serverRumEvent = withSnakeCaseKeys(rumEvent)
serverRumEvent.context = combine(savedGlobalContext || getGlobalContext(), customerContext)
lifeCycle.notify(LifeCycleEventType.RUM_EVENT_V2_COLLECTED, { rumEvent, serverRumEvent })
lifeCycle.notify(LifeCycleEventType.RUM_EVENT_COLLECTED, { rumEvent, serverRumEvent })
}
}
)
}

function needToAssembleWithAction(
event: RawRumEventV2
): event is RumErrorEventV2 | RumResourceEventV2 | RumLongTaskEventV2 {
event: RawRumEvent
): event is RumErrorEvent | RumResourceEvent | RumLongTaskEvent {
return [RumEventType.ERROR, RumEventType.RESOURCE, RumEventType.LONG_TASK].indexOf(event.type) !== -1
}

Expand Down
10 changes: 5 additions & 5 deletions packages/rum/src/domain/internalContext.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ import { setup, TestSetupBuilder } from '../../test/specHelper'
import { startInternalContext } from './internalContext'
import { ParentContexts } from './parentContexts'

describe('internal context v2', () => {
describe('internal context', () => {
let setupBuilder: TestSetupBuilder
let parentContextsStub: Partial<ParentContexts>
let internalContext: ReturnType<typeof startInternalContext>

beforeEach(() => {
parentContextsStub = {
findActionV2: jasmine.createSpy('findAction').and.returnValue({
findAction: jasmine.createSpy('findAction').and.returnValue({
action: {
id: '7890',
},
}),
findViewV2: jasmine.createSpy('findView').and.returnValue({
findView: jasmine.createSpy('findView').and.returnValue({
session: {
id: '1234',
},
Expand Down Expand Up @@ -70,7 +70,7 @@ describe('internal context v2', () => {

internalContext.get(123)

expect(parentContextsStub.findViewV2).toHaveBeenCalledWith(123)
expect(parentContextsStub.findActionV2).toHaveBeenCalledWith(123)
expect(parentContextsStub.findView).toHaveBeenCalledWith(123)
expect(parentContextsStub.findAction).toHaveBeenCalledWith(123)
})
})
6 changes: 3 additions & 3 deletions packages/rum/src/domain/internalContext.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { combine, withSnakeCaseKeys } from '@datadog/browser-core'
import { InternalContext } from '../typesV2'
import { InternalContext } from '../types'
import { ParentContexts } from './parentContexts'
import { RumSession } from './rumSession'

Expand All @@ -10,9 +10,9 @@ import { RumSession } from './rumSession'
export function startInternalContext(applicationId: string, session: RumSession, parentContexts: ParentContexts) {
return {
get: (startTime?: number) => {
const viewContext = parentContexts.findViewV2(startTime)
const viewContext = parentContexts.findView(startTime)
if (session.isTracked() && viewContext && viewContext.session.id) {
const actionContext = parentContexts.findActionV2(startTime)
const actionContext = parentContexts.findAction(startTime)
return (withSnakeCaseKeys(
combine(
{ applicationId },
Expand Down
Loading

0 comments on commit cf533ed

Please sign in to comment.