From c5decf4579bc106cc628bd2529872cfd5c2f0bf7 Mon Sep 17 00:00:00 2001 From: Bastien Caudan Date: Tue, 3 Dec 2019 17:52:08 +0100 Subject: [PATCH 1/4] :sparkles:[RUM] add view resource count --- packages/rum/src/lifeCycle.ts | 5 +++-- packages/rum/src/rum.ts | 7 +++++-- packages/rum/src/viewTracker.ts | 8 +++++++- packages/rum/test/rum.spec.ts | 21 ++++++++++++++++++--- packages/rum/test/viewTracker.spec.ts | 18 ++++++++++++++++++ 5 files changed, 51 insertions(+), 8 deletions(-) diff --git a/packages/rum/src/lifeCycle.ts b/packages/rum/src/lifeCycle.ts index 3a7bb516c7..f38d45c9cb 100644 --- a/packages/rum/src/lifeCycle.ts +++ b/packages/rum/src/lifeCycle.ts @@ -7,6 +7,7 @@ export enum LifeCycleEventType { userAction, request, renewSession, + rumResource, } export class LifeCycle { @@ -16,7 +17,7 @@ export class LifeCycle { notify(eventType: LifeCycleEventType.performance, data: PerformanceEntry): void notify(eventType: LifeCycleEventType.request, data: RequestDetails): void notify(eventType: LifeCycleEventType.userAction, data: UserAction): void - notify(eventType: LifeCycleEventType.renewSession): void + notify(eventType: LifeCycleEventType.renewSession | LifeCycleEventType.rumResource): void notify(eventType: LifeCycleEventType, data?: any) { const eventCallbacks = this.callbacks[eventType] if (eventCallbacks) { @@ -28,7 +29,7 @@ export class LifeCycle { subscribe(eventType: LifeCycleEventType.performance, callback: (data: PerformanceEntry) => void): void subscribe(eventType: LifeCycleEventType.request, callback: (data: RequestDetails) => void): void subscribe(eventType: LifeCycleEventType.userAction, callback: (data: UserAction) => void): void - subscribe(eventType: LifeCycleEventType.renewSession, callback: () => void): void + subscribe(eventType: LifeCycleEventType.renewSession | LifeCycleEventType.rumResource, callback: () => void): void subscribe(eventType: LifeCycleEventType, callback: (data?: any) => void) { const eventCallbacks = this.callbacks[eventType] if (eventCallbacks) { diff --git a/packages/rum/src/rum.ts b/packages/rum/src/rum.ts index a9c94915f8..2705d59272 100644 --- a/packages/rum/src/rum.ts +++ b/packages/rum/src/rum.ts @@ -276,6 +276,7 @@ export function trackRequests( }, traceId: requestDetails.traceId, }) + lifeCycle.notify(LifeCycleEventType.rumResource) }) } @@ -287,7 +288,7 @@ function trackPerformanceTiming( lifeCycle.subscribe(LifeCycleEventType.performance, (entry) => { switch (entry.entryType) { case 'resource': - handleResourceEntry(configuration, entry as PerformanceResourceTiming, addRumEvent) + handleResourceEntry(configuration, entry as PerformanceResourceTiming, addRumEvent, lifeCycle) break case 'longtask': handleLongTaskEntry(entry as PerformanceLongTaskTiming, addRumEvent) @@ -301,7 +302,8 @@ function trackPerformanceTiming( export function handleResourceEntry( configuration: Configuration, entry: PerformanceResourceTiming, - addRumEvent: (event: RumEvent) => void + addRumEvent: (event: RumEvent) => void, + lifeCycle: LifeCycle ) { if (!isValidResource(entry.name, configuration)) { return @@ -326,6 +328,7 @@ export function handleResourceEntry( kind: resourceKind, }, }) + lifeCycle.notify(LifeCycleEventType.rumResource) } export function handleLongTaskEntry(entry: PerformanceLongTaskTiming, addRumEvent: (event: RumEvent) => void) { diff --git a/packages/rum/src/viewTracker.ts b/packages/rum/src/viewTracker.ts index adba5a2ed5..a65b2ed353 100644 --- a/packages/rum/src/viewTracker.ts +++ b/packages/rum/src/viewTracker.ts @@ -9,9 +9,10 @@ export interface ViewMeasures { domContentLoaded?: number domComplete?: number loadEventEnd?: number - userActionCount: number errorCount: number + resourceCount: number longTaskCount: number + userActionCount: number } export let viewId: string @@ -49,6 +50,7 @@ function newView(location: Location, addRumEvent: (event: RumEvent) => void) { viewMeasures = { errorCount: 0, longTaskCount: 0, + resourceCount: 0, userActionCount: 0, } viewLocation = { ...location } @@ -138,6 +140,10 @@ function trackMeasures(lifeCycle: LifeCycle, scheduleViewUpdate: () => void) { scheduleViewUpdate() } }) + lifeCycle.subscribe(LifeCycleEventType.rumResource, () => { + viewMeasures.resourceCount += 1 + scheduleViewUpdate() + }) } function trackRenewSession(location: Location, lifeCycle: LifeCycle, addRumEvent: (event: RumEvent) => void) { diff --git a/packages/rum/test/rum.spec.ts b/packages/rum/test/rum.spec.ts index 43ab6ed73f..ad41204b34 100644 --- a/packages/rum/test/rum.spec.ts +++ b/packages/rum/test/rum.spec.ts @@ -72,7 +72,12 @@ describe('rum handle performance entry', () => { expectEntryToBeAdded: boolean }) => { it(description, () => { - handleResourceEntry(configuration as Configuration, entry as PerformanceResourceTiming, addRumEvent) + handleResourceEntry( + configuration as Configuration, + entry as PerformanceResourceTiming, + addRumEvent, + new LifeCycle() + ) const entryAdded = (addRumEvent as jasmine.Spy).calls.all().length !== 0 expect(entryAdded).toEqual(expectEntryToBeAdded) }) @@ -115,7 +120,12 @@ describe('rum handle performance entry', () => { it(`should compute resource kind: ${description}`, () => { const entry: Partial = { initiatorType, name: url, entryType: 'resource' } - handleResourceEntry(configuration as Configuration, entry as PerformanceResourceTiming, addRumEvent) + handleResourceEntry( + configuration as Configuration, + entry as PerformanceResourceTiming, + addRumEvent, + new LifeCycle() + ) const resourceEvent = getEntry(addRumEvent, 0) as RumResourceEvent expect(resourceEvent.resource.kind).toEqual(expected) }) @@ -132,7 +142,12 @@ describe('rum handle performance entry', () => { responseStart: 25, } - handleResourceEntry(configuration as Configuration, entry as PerformanceResourceTiming, addRumEvent) + handleResourceEntry( + configuration as Configuration, + entry as PerformanceResourceTiming, + addRumEvent, + new LifeCycle() + ) const resourceEvent = getEntry(addRumEvent, 0) as RumResourceEvent expect(resourceEvent.http.performance!.connect.duration).toEqual(7 * 1e6) expect(resourceEvent.http.performance!.download.duration).toEqual(75 * 1e6) diff --git a/packages/rum/test/viewTracker.spec.ts b/packages/rum/test/viewTracker.spec.ts index edef71dcf4..15d4a026cf 100644 --- a/packages/rum/test/viewTracker.spec.ts +++ b/packages/rum/test/viewTracker.spec.ts @@ -132,6 +132,21 @@ describe('rum view measures', () => { expect(getViewEvent(2).view.measures.longTaskCount).toEqual(0) }) + it('should track resource count', () => { + const lifeCycle = new LifeCycle() + setup({ addRumEvent, lifeCycle }) + + expect(getEventCount()).toEqual(1) + expect(getViewEvent(0).view.measures.resourceCount).toEqual(0) + + lifeCycle.notify(LifeCycleEventType.rumResource) + history.pushState({}, '', '/bar') + + expect(getEventCount()).toEqual(3) + expect(getViewEvent(1).view.measures.resourceCount).toEqual(1) + expect(getViewEvent(2).view.measures.resourceCount).toEqual(0) + }) + it('should track user action count', () => { const lifeCycle = new LifeCycle() setup({ addRumEvent, lifeCycle }) @@ -155,6 +170,7 @@ describe('rum view measures', () => { expect(getViewEvent(0).view.measures).toEqual({ errorCount: 0, longTaskCount: 0, + resourceCount: 0, userActionCount: 0, }) @@ -171,11 +187,13 @@ describe('rum view measures', () => { firstContentfulPaint: 123e6, loadEventEnd: 567e6, longTaskCount: 0, + resourceCount: 0, userActionCount: 0, }) expect(getViewEvent(2).view.measures).toEqual({ errorCount: 0, longTaskCount: 0, + resourceCount: 0, userActionCount: 0, }) }) From 01aa64adb19a18c2303d0a11e52f4f81d43edb38 Mon Sep 17 00:00:00 2001 From: Bastien Caudan Date: Tue, 3 Dec 2019 18:38:51 +0100 Subject: [PATCH 2/4] :white_check_mark:[e2e] add missing expectation --- test/e2e/scenario/agents.scenario.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/test/e2e/scenario/agents.scenario.ts b/test/e2e/scenario/agents.scenario.ts index 1e8803cc53..85a2a67a59 100644 --- a/test/e2e/scenario/agents.scenario.ts +++ b/test/e2e/scenario/agents.scenario.ts @@ -121,6 +121,7 @@ describe('rum', () => { error_count: 0, load_event_end: strictlyPositiveNumber(), long_task_count: 0, + resource_count: 0, user_action_count: 0, } as any) }) From ec56d6ab1fe87eca9c147c2413c9052381b14ec2 Mon Sep 17 00:00:00 2001 From: Bastien Caudan Date: Wed, 4 Dec 2019 10:57:08 +0100 Subject: [PATCH 3/4] :white_check_mark:[e2e cbt] fix wrong expectation on safari, there is a resource event for the current page --- test/e2e/scenario/agents.scenario.ts | 4 ++-- test/e2e/scenario/matchers.ts | 14 +++++++++++++- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/test/e2e/scenario/agents.scenario.ts b/test/e2e/scenario/agents.scenario.ts index 85a2a67a59..598915a314 100644 --- a/test/e2e/scenario/agents.scenario.ts +++ b/test/e2e/scenario/agents.scenario.ts @@ -16,7 +16,7 @@ import { tearDown, withBrowserLogs, } from './helpers' -import { strictlyPositiveNumber } from './matchers' +import { positiveNumber, strictlyPositiveNumber } from './matchers' beforeEach(() => { // tslint:disable-next-line: no-unsafe-any @@ -121,7 +121,7 @@ describe('rum', () => { error_count: 0, load_event_end: strictlyPositiveNumber(), long_task_count: 0, - resource_count: 0, + resource_count: positiveNumber(), // some browsers can send a resource for the page load user_action_count: 0, } as any) }) diff --git a/test/e2e/scenario/matchers.ts b/test/e2e/scenario/matchers.ts index 411f00a57d..dca2474da6 100644 --- a/test/e2e/scenario/matchers.ts +++ b/test/e2e/scenario/matchers.ts @@ -4,8 +4,20 @@ class StrictlyPositiveNumber { } jasmineToString() { - return '' + return '' } } export const strictlyPositiveNumber = () => new StrictlyPositiveNumber() + +class PositiveNumber { + asymmetricMatch(other: any) { + return typeof other === 'number' && !isNaN(other) && other >= 0 + } + + jasmineToString() { + return '' + } +} + +export const positiveNumber = () => new PositiveNumber() From 73e1316e6c0f9b92448e7cea77b808ac80acec8a Mon Sep 17 00:00:00 2001 From: Bastien Caudan Date: Wed, 4 Dec 2019 11:27:08 +0100 Subject: [PATCH 4/4] :ok_hand:[RUM] rename life cycle events --- packages/rum/src/lifeCycle.ts | 35 ++++++++++++----------- packages/rum/src/performanceCollection.ts | 2 +- packages/rum/src/rum.entry.ts | 6 ++-- packages/rum/src/rum.ts | 14 ++++----- packages/rum/src/rumSession.ts | 2 +- packages/rum/src/viewTracker.ts | 12 ++++---- packages/rum/test/rum.spec.ts | 32 ++++++++++----------- packages/rum/test/rumSession.spec.ts | 2 +- packages/rum/test/viewTracker.spec.ts | 19 ++++++------ 9 files changed, 66 insertions(+), 58 deletions(-) diff --git a/packages/rum/src/lifeCycle.ts b/packages/rum/src/lifeCycle.ts index f38d45c9cb..c0caa10f06 100644 --- a/packages/rum/src/lifeCycle.ts +++ b/packages/rum/src/lifeCycle.ts @@ -2,22 +2,22 @@ import { ErrorMessage, RequestDetails } from '@browser-sdk/core' import { UserAction } from './rum' export enum LifeCycleEventType { - error, - performance, - userAction, - request, - renewSession, - rumResource, + ERROR_COLLECTED, + PERFORMANCE_ENTRY_COLLECTED, + USER_ACTION_COLLECTED, + REQUEST_COLLECTED, + SESSION_RENEWED, + RESOURCE_ADDED_TO_BATCH, } export class LifeCycle { private callbacks: { [key in LifeCycleEventType]?: Array<(data: any) => void> } = {} - notify(eventType: LifeCycleEventType.error, data: ErrorMessage): void - notify(eventType: LifeCycleEventType.performance, data: PerformanceEntry): void - notify(eventType: LifeCycleEventType.request, data: RequestDetails): void - notify(eventType: LifeCycleEventType.userAction, data: UserAction): void - notify(eventType: LifeCycleEventType.renewSession | LifeCycleEventType.rumResource): void + notify(eventType: LifeCycleEventType.ERROR_COLLECTED, data: ErrorMessage): void + notify(eventType: LifeCycleEventType.PERFORMANCE_ENTRY_COLLECTED, data: PerformanceEntry): void + notify(eventType: LifeCycleEventType.REQUEST_COLLECTED, data: RequestDetails): void + notify(eventType: LifeCycleEventType.USER_ACTION_COLLECTED, data: UserAction): void + notify(eventType: LifeCycleEventType.SESSION_RENEWED | LifeCycleEventType.RESOURCE_ADDED_TO_BATCH): void notify(eventType: LifeCycleEventType, data?: any) { const eventCallbacks = this.callbacks[eventType] if (eventCallbacks) { @@ -25,11 +25,14 @@ export class LifeCycle { } } - subscribe(eventType: LifeCycleEventType.error, callback: (data: ErrorMessage) => void): void - subscribe(eventType: LifeCycleEventType.performance, callback: (data: PerformanceEntry) => void): void - subscribe(eventType: LifeCycleEventType.request, callback: (data: RequestDetails) => void): void - subscribe(eventType: LifeCycleEventType.userAction, callback: (data: UserAction) => void): void - subscribe(eventType: LifeCycleEventType.renewSession | LifeCycleEventType.rumResource, callback: () => void): void + subscribe(eventType: LifeCycleEventType.ERROR_COLLECTED, callback: (data: ErrorMessage) => void): void + subscribe(eventType: LifeCycleEventType.PERFORMANCE_ENTRY_COLLECTED, callback: (data: PerformanceEntry) => void): void + subscribe(eventType: LifeCycleEventType.REQUEST_COLLECTED, callback: (data: RequestDetails) => void): void + subscribe(eventType: LifeCycleEventType.USER_ACTION_COLLECTED, callback: (data: UserAction) => void): void + subscribe( + eventType: LifeCycleEventType.SESSION_RENEWED | LifeCycleEventType.RESOURCE_ADDED_TO_BATCH, + callback: () => void + ): void subscribe(eventType: LifeCycleEventType, callback: (data?: any) => void) { const eventCallbacks = this.callbacks[eventType] if (eventCallbacks) { diff --git a/packages/rum/src/performanceCollection.ts b/packages/rum/src/performanceCollection.ts index 2d6785673c..6c851be32d 100644 --- a/packages/rum/src/performanceCollection.ts +++ b/packages/rum/src/performanceCollection.ts @@ -80,7 +80,7 @@ function retrieveNavigationTimingWhenLoaded(callback: (timing: PerformanceNaviga function handlePerformanceEntries(session: RumSession, lifeCycle: LifeCycle, entries: PerformanceEntry[]) { function notify(entry: PerformanceEntry) { - lifeCycle.notify(LifeCycleEventType.performance, entry) + lifeCycle.notify(LifeCycleEventType.PERFORMANCE_ENTRY_COLLECTED, entry) } if (session.isTrackedWithResource()) { diff --git a/packages/rum/src/rum.entry.ts b/packages/rum/src/rum.entry.ts index 6a71c1a0b7..a196f5bbbf 100644 --- a/packages/rum/src/rum.entry.ts +++ b/packages/rum/src/rum.entry.ts @@ -89,8 +89,10 @@ datadogRum.init = monitor((userConfiguration: RumUserConfiguration) => { const requestObservable = startRequestCollection() startPerformanceCollection(lifeCycle, session) - errorObservable.subscribe((errorMessage) => lifeCycle.notify(LifeCycleEventType.error, errorMessage)) - requestObservable.subscribe((requestDetails) => lifeCycle.notify(LifeCycleEventType.request, requestDetails)) + errorObservable.subscribe((errorMessage) => lifeCycle.notify(LifeCycleEventType.ERROR_COLLECTED, errorMessage)) + requestObservable.subscribe((requestDetails) => + lifeCycle.notify(LifeCycleEventType.REQUEST_COLLECTED, requestDetails) + ) const globalApi = startRum(rumUserConfiguration.applicationId, lifeCycle, configuration, session) lodashAssign(datadogRum, globalApi) diff --git a/packages/rum/src/rum.ts b/packages/rum/src/rum.ts index 2705d59272..34583e945e 100644 --- a/packages/rum/src/rum.ts +++ b/packages/rum/src/rum.ts @@ -166,7 +166,7 @@ export function startRum( globalContext[key] = value }), addUserAction: monitor((name: string, context?: Context) => { - lifeCycle.notify(LifeCycleEventType.userAction, { name, context }) + lifeCycle.notify(LifeCycleEventType.USER_ACTION_COLLECTED, { name, context }) }), getInternalContext: monitor(() => { return { @@ -213,7 +213,7 @@ function startRumBatch( } function trackErrors(lifeCycle: LifeCycle, addRumEvent: (event: RumEvent) => void) { - lifeCycle.subscribe(LifeCycleEventType.error, ({ message, context }: ErrorMessage) => { + lifeCycle.subscribe(LifeCycleEventType.ERROR_COLLECTED, ({ message, context }: ErrorMessage) => { addRumEvent({ message, evt: { @@ -228,7 +228,7 @@ function trackErrors(lifeCycle: LifeCycle, addRumEvent: (event: RumEvent) => voi } function trackUserAction(lifeCycle: LifeCycle, addUserEvent: (event: RumUserAction) => void) { - lifeCycle.subscribe(LifeCycleEventType.userAction, ({ name, context }) => { + lifeCycle.subscribe(LifeCycleEventType.USER_ACTION_COLLECTED, ({ name, context }) => { addUserEvent({ ...context, evt: { @@ -245,7 +245,7 @@ export function trackRequests( session: RumSession, addRumEvent: (event: RumEvent) => void ) { - lifeCycle.subscribe(LifeCycleEventType.request, (requestDetails: RequestDetails) => { + lifeCycle.subscribe(LifeCycleEventType.REQUEST_COLLECTED, (requestDetails: RequestDetails) => { if (!session.isTrackedWithResource()) { return } @@ -276,7 +276,7 @@ export function trackRequests( }, traceId: requestDetails.traceId, }) - lifeCycle.notify(LifeCycleEventType.rumResource) + lifeCycle.notify(LifeCycleEventType.RESOURCE_ADDED_TO_BATCH) }) } @@ -285,7 +285,7 @@ function trackPerformanceTiming( lifeCycle: LifeCycle, addRumEvent: (event: RumEvent) => void ) { - lifeCycle.subscribe(LifeCycleEventType.performance, (entry) => { + lifeCycle.subscribe(LifeCycleEventType.PERFORMANCE_ENTRY_COLLECTED, (entry) => { switch (entry.entryType) { case 'resource': handleResourceEntry(configuration, entry as PerformanceResourceTiming, addRumEvent, lifeCycle) @@ -328,7 +328,7 @@ export function handleResourceEntry( kind: resourceKind, }, }) - lifeCycle.notify(LifeCycleEventType.rumResource) + lifeCycle.notify(LifeCycleEventType.RESOURCE_ADDED_TO_BATCH) } export function handleLongTaskEntry(entry: PerformanceLongTaskTiming, addRumEvent: (event: RumEvent) => void) { diff --git a/packages/rum/src/rumSession.ts b/packages/rum/src/rumSession.ts index fd8fd87fe9..98f3a484fb 100644 --- a/packages/rum/src/rumSession.ts +++ b/packages/rum/src/rumSession.ts @@ -19,7 +19,7 @@ export function startRumSession(configuration: Configuration, lifeCycle: LifeCyc const session = startSessionManagement(RUM_COOKIE_NAME, (rawType) => computeSessionState(configuration, rawType)) session.renewObservable.subscribe(() => { - lifeCycle.notify(LifeCycleEventType.renewSession) + lifeCycle.notify(LifeCycleEventType.SESSION_RENEWED) }) return { diff --git a/packages/rum/src/viewTracker.ts b/packages/rum/src/viewTracker.ts index a65b2ed353..8b1819fc6d 100644 --- a/packages/rum/src/viewTracker.ts +++ b/packages/rum/src/viewTracker.ts @@ -106,7 +106,7 @@ function areDifferentViews(previous: Location, current: Location) { } function trackMeasures(lifeCycle: LifeCycle, scheduleViewUpdate: () => void) { - lifeCycle.subscribe(LifeCycleEventType.performance, (entry) => { + lifeCycle.subscribe(LifeCycleEventType.PERFORMANCE_ENTRY_COLLECTED, (entry) => { if (entry.entryType === 'navigation') { const navigationEntry = entry as PerformanceNavigationTiming viewMeasures = { @@ -126,28 +126,28 @@ function trackMeasures(lifeCycle: LifeCycle, scheduleViewUpdate: () => void) { scheduleViewUpdate() } }) - lifeCycle.subscribe(LifeCycleEventType.error, () => { + lifeCycle.subscribe(LifeCycleEventType.ERROR_COLLECTED, () => { viewMeasures.errorCount += 1 scheduleViewUpdate() }) - lifeCycle.subscribe(LifeCycleEventType.userAction, () => { + lifeCycle.subscribe(LifeCycleEventType.USER_ACTION_COLLECTED, () => { viewMeasures.userActionCount += 1 scheduleViewUpdate() }) - lifeCycle.subscribe(LifeCycleEventType.performance, (entry) => { + lifeCycle.subscribe(LifeCycleEventType.PERFORMANCE_ENTRY_COLLECTED, (entry) => { if (entry.entryType === 'longtask') { viewMeasures.longTaskCount += 1 scheduleViewUpdate() } }) - lifeCycle.subscribe(LifeCycleEventType.rumResource, () => { + lifeCycle.subscribe(LifeCycleEventType.RESOURCE_ADDED_TO_BATCH, () => { viewMeasures.resourceCount += 1 scheduleViewUpdate() }) } function trackRenewSession(location: Location, lifeCycle: LifeCycle, addRumEvent: (event: RumEvent) => void) { - lifeCycle.subscribe(LifeCycleEventType.renewSession, () => { + lifeCycle.subscribe(LifeCycleEventType.SESSION_RENEWED, () => { updateView(addRumEvent) newView(location, addRumEvent) }) diff --git a/packages/rum/test/rum.spec.ts b/packages/rum/test/rum.spec.ts index ad41204b34..615f5f9eb6 100644 --- a/packages/rum/test/rum.spec.ts +++ b/packages/rum/test/rum.spec.ts @@ -190,9 +190,9 @@ describe('rum session', () => { server.requests = [] stubBuilder.fakeEntry(FAKE_RESOURCE as PerformanceEntry, 'resource') - lifeCycle.notify(LifeCycleEventType.error, FAKE_ERROR as ErrorMessage) - lifeCycle.notify(LifeCycleEventType.request, FAKE_REQUEST as RequestDetails) - lifeCycle.notify(LifeCycleEventType.userAction, FAKE_USER_ACTION) + lifeCycle.notify(LifeCycleEventType.ERROR_COLLECTED, FAKE_ERROR as ErrorMessage) + lifeCycle.notify(LifeCycleEventType.REQUEST_COLLECTED, FAKE_REQUEST as RequestDetails) + lifeCycle.notify(LifeCycleEventType.USER_ACTION_COLLECTED, FAKE_USER_ACTION) expect(server.requests.length).toEqual(4) }) @@ -209,10 +209,10 @@ describe('rum session', () => { server.requests = [] stubBuilder.fakeEntry(FAKE_RESOURCE as PerformanceEntry, 'resource') - lifeCycle.notify(LifeCycleEventType.request, FAKE_REQUEST as RequestDetails) + lifeCycle.notify(LifeCycleEventType.REQUEST_COLLECTED, FAKE_REQUEST as RequestDetails) expect(server.requests.length).toEqual(0) - lifeCycle.notify(LifeCycleEventType.error, FAKE_ERROR as ErrorMessage) + lifeCycle.notify(LifeCycleEventType.ERROR_COLLECTED, FAKE_ERROR as ErrorMessage) expect(server.requests.length).toEqual(1) }) @@ -228,9 +228,9 @@ describe('rum session', () => { server.requests = [] stubBuilder.fakeEntry(FAKE_RESOURCE as PerformanceEntry, 'resource') - lifeCycle.notify(LifeCycleEventType.request, FAKE_REQUEST as RequestDetails) - lifeCycle.notify(LifeCycleEventType.error, FAKE_ERROR as ErrorMessage) - lifeCycle.notify(LifeCycleEventType.userAction, FAKE_USER_ACTION) + lifeCycle.notify(LifeCycleEventType.REQUEST_COLLECTED, FAKE_REQUEST as RequestDetails) + lifeCycle.notify(LifeCycleEventType.ERROR_COLLECTED, FAKE_ERROR as ErrorMessage) + lifeCycle.notify(LifeCycleEventType.USER_ACTION_COLLECTED, FAKE_USER_ACTION) expect(server.requests.length).toEqual(0) }) @@ -271,15 +271,15 @@ describe('rum session', () => { startPerformanceCollection(lifeCycle, session) server.requests = [] - lifeCycle.notify(LifeCycleEventType.request, FAKE_REQUEST as RequestDetails) + lifeCycle.notify(LifeCycleEventType.REQUEST_COLLECTED, FAKE_REQUEST as RequestDetails) expect(server.requests.length).toEqual(1) isTrackedWithResource = false - lifeCycle.notify(LifeCycleEventType.request, FAKE_REQUEST as RequestDetails) + lifeCycle.notify(LifeCycleEventType.REQUEST_COLLECTED, FAKE_REQUEST as RequestDetails) expect(server.requests.length).toEqual(1) isTrackedWithResource = true - lifeCycle.notify(LifeCycleEventType.request, FAKE_REQUEST as RequestDetails) + lifeCycle.notify(LifeCycleEventType.REQUEST_COLLECTED, FAKE_REQUEST as RequestDetails) expect(server.requests.length).toEqual(2) }) }) @@ -340,16 +340,16 @@ describe('rum global context', () => { it('should be added to the request', () => { RUM.setRumGlobalContext({ bar: 'foo' }) - lifeCycle.notify(LifeCycleEventType.error, FAKE_ERROR as ErrorMessage) + lifeCycle.notify(LifeCycleEventType.ERROR_COLLECTED, FAKE_ERROR as ErrorMessage) expect((getRumMessage(server, 0) as any).bar).toEqual('foo') }) it('should be updatable', () => { RUM.setRumGlobalContext({ bar: 'foo' }) - lifeCycle.notify(LifeCycleEventType.error, FAKE_ERROR as ErrorMessage) + lifeCycle.notify(LifeCycleEventType.ERROR_COLLECTED, FAKE_ERROR as ErrorMessage) RUM.setRumGlobalContext({ foo: 'bar' }) - lifeCycle.notify(LifeCycleEventType.error, FAKE_ERROR as ErrorMessage) + lifeCycle.notify(LifeCycleEventType.ERROR_COLLECTED, FAKE_ERROR as ErrorMessage) expect((getRumMessage(server, 0) as any).bar).toEqual('foo') expect((getRumMessage(server, 1) as any).foo).toEqual('bar') @@ -358,7 +358,7 @@ describe('rum global context', () => { it('should not be automatically snake cased', () => { RUM.setRumGlobalContext({ fooBar: 'foo' }) - lifeCycle.notify(LifeCycleEventType.error, FAKE_ERROR as ErrorMessage) + lifeCycle.notify(LifeCycleEventType.ERROR_COLLECTED, FAKE_ERROR as ErrorMessage) expect((getRumMessage(server, 0) as any).fooBar).toEqual('foo') }) @@ -382,7 +382,7 @@ describe('rum user action', () => { }) it('should not be automatically snake cased', () => { - lifeCycle.notify(LifeCycleEventType.userAction, { name: 'hello', context: { fooBar: 'foo' } }) + lifeCycle.notify(LifeCycleEventType.USER_ACTION_COLLECTED, { name: 'hello', context: { fooBar: 'foo' } }) expect((getRumMessage(server, 0) as any).fooBar).toEqual('foo') }) diff --git a/packages/rum/test/rumSession.spec.ts b/packages/rum/test/rumSession.spec.ts index 52c8ea29c3..dc8f98ab43 100644 --- a/packages/rum/test/rumSession.spec.ts +++ b/packages/rum/test/rumSession.spec.ts @@ -34,7 +34,7 @@ describe('rum session', () => { jasmine.clock().mockDate(new Date()) renewSessionSpy = jasmine.createSpy('renewSessionSpy') lifeCycle = new LifeCycle() - lifeCycle.subscribe(LifeCycleEventType.renewSession, renewSessionSpy) + lifeCycle.subscribe(LifeCycleEventType.SESSION_RENEWED, renewSessionSpy) }) afterEach(() => { diff --git a/packages/rum/test/viewTracker.spec.ts b/packages/rum/test/viewTracker.spec.ts index 15d4a026cf..b25128eda4 100644 --- a/packages/rum/test/viewTracker.spec.ts +++ b/packages/rum/test/viewTracker.spec.ts @@ -58,7 +58,7 @@ describe('rum track renew session', () => { lifeCycle, }) const initialView = viewId - lifeCycle.notify(LifeCycleEventType.renewSession) + lifeCycle.notify(LifeCycleEventType.SESSION_RENEWED) expect(viewId).not.toEqual(initialView) }) @@ -108,8 +108,8 @@ describe('rum view measures', () => { expect(getEventCount()).toEqual(1) expect(getViewEvent(0).view.measures.errorCount).toEqual(0) - lifeCycle.notify(LifeCycleEventType.error, {} as any) - lifeCycle.notify(LifeCycleEventType.error, {} as any) + lifeCycle.notify(LifeCycleEventType.ERROR_COLLECTED, {} as any) + lifeCycle.notify(LifeCycleEventType.ERROR_COLLECTED, {} as any) history.pushState({}, '', '/bar') expect(getEventCount()).toEqual(3) @@ -124,7 +124,7 @@ describe('rum view measures', () => { expect(getEventCount()).toEqual(1) expect(getViewEvent(0).view.measures.longTaskCount).toEqual(0) - lifeCycle.notify(LifeCycleEventType.performance, FAKE_LONG_TASK as PerformanceLongTaskTiming) + lifeCycle.notify(LifeCycleEventType.PERFORMANCE_ENTRY_COLLECTED, FAKE_LONG_TASK as PerformanceLongTaskTiming) history.pushState({}, '', '/bar') expect(getEventCount()).toEqual(3) @@ -139,7 +139,7 @@ describe('rum view measures', () => { expect(getEventCount()).toEqual(1) expect(getViewEvent(0).view.measures.resourceCount).toEqual(0) - lifeCycle.notify(LifeCycleEventType.rumResource) + lifeCycle.notify(LifeCycleEventType.RESOURCE_ADDED_TO_BATCH) history.pushState({}, '', '/bar') expect(getEventCount()).toEqual(3) @@ -154,7 +154,7 @@ describe('rum view measures', () => { expect(getEventCount()).toEqual(1) expect(getViewEvent(0).view.measures.userActionCount).toEqual(0) - lifeCycle.notify(LifeCycleEventType.userAction, FAKE_USER_ACTION as UserAction) + lifeCycle.notify(LifeCycleEventType.USER_ACTION_COLLECTED, FAKE_USER_ACTION as UserAction) history.pushState({}, '', '/bar') expect(getEventCount()).toEqual(3) @@ -174,8 +174,11 @@ describe('rum view measures', () => { userActionCount: 0, }) - lifeCycle.notify(LifeCycleEventType.performance, FAKE_PAINT_ENTRY as PerformancePaintTiming) - lifeCycle.notify(LifeCycleEventType.performance, FAKE_NAVIGATION_ENTRY as PerformanceNavigationTiming) + lifeCycle.notify(LifeCycleEventType.PERFORMANCE_ENTRY_COLLECTED, FAKE_PAINT_ENTRY as PerformancePaintTiming) + lifeCycle.notify( + LifeCycleEventType.PERFORMANCE_ENTRY_COLLECTED, + FAKE_NAVIGATION_ENTRY as PerformanceNavigationTiming + ) history.pushState({}, '', '/bar') expect(getEventCount()).toEqual(3)