Skip to content

Commit ff4b0a9

Browse files
♻️ move long task contexts to profiler (#4046)
1 parent 37e7fa9 commit ff4b0a9

36 files changed

+537
-160
lines changed

packages/rum-core/src/boot/rumPublicApi.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ const noopStartRum = (): ReturnType<StartRum> => ({
3737
getInternalContext: () => undefined,
3838
lifeCycle: {} as any,
3939
viewHistory: {} as any,
40-
longTaskContexts: {} as any,
4140
session: {} as any,
4241
stopSession: () => undefined,
4342
startDurationVital: () => ({}) as DurationVitalReference,

packages/rum-core/src/boot/rumPublicApi.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ import { createCustomVitalsState } from '../domain/vital/vitalCollection'
5656
import { callPluginsMethod } from '../domain/plugins'
5757
import type { Hooks } from '../domain/hooks'
5858
import type { SdkName } from '../domain/contexts/defaultContext'
59-
import type { LongTaskContexts } from '../domain/longTask/longTaskCollection'
6059
import type { ActionOptions } from '../domain/action/trackManualActions'
6160
import type { ResourceOptions, ResourceStopOptions } from '../domain/resource/trackManualResources'
6261
import { createPreStartStrategy } from './preStartRum'
@@ -528,7 +527,6 @@ export interface ProfilerApi {
528527
configuration: RumConfiguration,
529528
sessionManager: RumSessionManager,
530529
viewHistory: ViewHistory,
531-
longTaskContexts: LongTaskContexts,
532530
createEncoder: (streamId: DeflateEncoderStreamId) => Encoder
533531
) => void
534532
}
@@ -626,7 +624,6 @@ export function makeRumPublicApi(
626624
configuration,
627625
startRumResult.session,
628626
startRumResult.viewHistory,
629-
startRumResult.longTaskContexts,
630627
createEncoder
631628
)
632629

packages/rum-core/src/boot/startRum.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ export function startRumEventCollection(
227227
const resourceCollection = startResourceCollection(lifeCycle, configuration, pageStateHistory)
228228
cleanupTasks.push(resourceCollection.stop)
229229

230-
const { stop: stopLongTaskCollection, longTaskContexts } = startLongTaskCollection(lifeCycle, configuration)
230+
const { stop: stopLongTaskCollection } = startLongTaskCollection(lifeCycle, configuration)
231231
cleanupTasks.push(stopLongTaskCollection)
232232

233233
const { addError } = startErrorCollection(lifeCycle, configuration, bufferedDataObservable)
@@ -268,7 +268,6 @@ export function startRumEventCollection(
268268
globalContext,
269269
userContext,
270270
accountContext,
271-
longTaskContexts,
272271
stop: () => cleanupTasks.forEach((task) => task()),
273272
}
274273
}

packages/rum-core/src/domain/action/actionCollection.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ describe('actionCollection', () => {
6464
events: [event],
6565
})
6666

67-
expect(rawRumEvents[0].startTime).toBe(1234 as RelativeTime)
67+
expect(rawRumEvents[0].startClocks.relative).toBe(1234 as RelativeTime)
6868
expect(rawRumEvents[0].rawRumEvent).toEqual({
6969
action: {
7070
error: {
@@ -116,7 +116,7 @@ describe('actionCollection', () => {
116116
context: { foo: 'bar' },
117117
})
118118

119-
expect(rawRumEvents[0].startTime).toBe(1234 as RelativeTime)
119+
expect(rawRumEvents[0].startClocks.relative).toBe(1234 as RelativeTime)
120120
expect(rawRumEvents[0].rawRumEvent).toEqual({
121121
action: {
122122
id: jasmine.any(String),

packages/rum-core/src/domain/action/actionCollection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ function processAction(action: AutoAction | ManualAction): RawRumEventCollectedD
138138
: { context: action.context }),
139139
},
140140
duration: action.duration,
141-
startTime: action.startClocks.relative,
141+
startClocks: action.startClocks,
142142
domainContext: isAuto ? { events: action.events } : { handlingStack: action.handlingStack },
143143
}
144144
}

packages/rum-core/src/domain/assembly.spec.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import type { ClocksState, RelativeTime, TimeStamp } from '@datadog/browser-core'
2-
import { ErrorSource, HookNames, ONE_MINUTE, display, startGlobalContext } from '@datadog/browser-core'
2+
import {
3+
ErrorSource,
4+
HookNames,
5+
ONE_MINUTE,
6+
display,
7+
relativeToClocks,
8+
startGlobalContext,
9+
} from '@datadog/browser-core'
310
import type { Clock } from '@datadog/browser-core/test'
411
import { registerCleanupTask, mockClock } from '@datadog/browser-core/test'
512
import {
@@ -461,7 +468,7 @@ describe('rum assembly', () => {
461468

462469
notifyRawRumEvent(lifeCycle, {
463470
rawRumEvent: createRawRumEvent(RumEventType.ACTION),
464-
startTime: 123 as RelativeTime,
471+
startClocks: relativeToClocks(123 as RelativeTime),
465472
})
466473

467474
expect(sessionManager.findTrackedSession).toHaveBeenCalledWith(123 as RelativeTime)
@@ -567,11 +574,11 @@ describe('rum assembly', () => {
567574

568575
function notifyRawRumEvent<E extends RawRumEvent>(
569576
lifeCycle: LifeCycle,
570-
partialData: Omit<RawRumEventCollectedData<E>, 'startTime' | 'domainContext'> &
571-
Partial<Pick<RawRumEventCollectedData<E>, 'startTime' | 'domainContext'>>
577+
partialData: Omit<RawRumEventCollectedData<E>, 'startClocks' | 'domainContext'> &
578+
Partial<Pick<RawRumEventCollectedData<E>, 'startClocks' | 'domainContext'>>
572579
) {
573580
const fullData = {
574-
startTime: 0 as RelativeTime,
581+
startClocks: relativeToClocks(0 as RelativeTime),
575582
domainContext: {} as RumEventDomainContext,
576583
...partialData,
577584
}

packages/rum-core/src/domain/assembly.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,12 @@ export function startRumAssembly(
9292

9393
lifeCycle.subscribe(
9494
LifeCycleEventType.RAW_RUM_EVENT_COLLECTED,
95-
({ startTime, duration, rawRumEvent, domainContext }) => {
95+
({ startClocks, duration, rawRumEvent, domainContext }) => {
9696
const defaultRumEventAttributes = hooks.triggerHook(HookNames.Assemble, {
9797
eventType: rawRumEvent.type,
9898
rawRumEvent,
9999
domainContext,
100-
startTime,
100+
startTime: startClocks.relative,
101101
duration,
102102
} as AssembleHookParams)!
103103

packages/rum-core/src/domain/error/errorCollection.spec.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,11 @@ describe('error collection', () => {
6565
it(`notifies a raw rum error event from ${testCase}`, () => {
6666
setupErrorCollection()
6767

68+
const startClocks = { relative: 1234 as RelativeTime, timeStamp: 123456789 as TimeStamp }
6869
addError({
6970
error,
7071
handlingStack: 'Error: handling foo',
71-
startClocks: { relative: 1234 as RelativeTime, timeStamp: 123456789 as TimeStamp },
72+
startClocks,
7273
})
7374

7475
expect(rawRumEvents.length).toBe(1)
@@ -92,7 +93,7 @@ describe('error collection', () => {
9293
type: RumEventType.ERROR,
9394
context: undefined,
9495
},
95-
startTime: 1234 as RelativeTime,
96+
startClocks,
9697
domainContext: {
9798
error,
9899
handlingStack: 'Error: handling foo',
@@ -239,7 +240,7 @@ describe('error collection', () => {
239240
},
240241
})
241242

242-
expect(rawRumEvents[0].startTime).toBe(1234 as RelativeTime)
243+
expect(rawRumEvents[0].startClocks.relative).toBe(1234 as RelativeTime)
243244
expect(rawRumEvents[0].rawRumEvent).toEqual({
244245
date: jasmine.any(Number),
245246
error: {

packages/rum-core/src/domain/error/errorCollection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ function processError(error: RawError): RawRumEventCollectedData<RawRumErrorEven
9898

9999
return {
100100
rawRumEvent,
101-
startTime: error.startClocks.relative,
101+
startClocks: error.startClocks,
102102
domainContext,
103103
}
104104
}

packages/rum-core/src/domain/event/eventCollection.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ describe('eventCollection', () => {
3333
eventCollection.addEvent(startTime, event, domainContext, duration)
3434

3535
expect(notifySpy).toHaveBeenCalledWith(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {
36-
startTime,
36+
startClocks: { relative: startTime, timeStamp: jasmine.any(Number) },
3737
rawRumEvent: event,
3838
domainContext,
3939
duration,

0 commit comments

Comments
 (0)