Skip to content

Commit da06b69

Browse files
Integrate add_profile_model_from_R-E-F (#4080) into staging-03
Integrated commit sha: b5feb14 Co-authored-by: BeltranBulbarellaDD <beltran.bulbarella@datadoghq.com>
2 parents 3908a1a + b5feb14 commit da06b69

File tree

10 files changed

+287
-76
lines changed

10 files changed

+287
-76
lines changed

packages/rum/src/domain/profiling/profiler.spec.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,10 @@ import {
2323
import { LONG_TASK_ID_HISTORY_TIME_OUT_DELAY } from 'packages/rum-core/src/domain/longTask/longTaskCollection'
2424
import { createRumSessionManagerMock, mockRumConfiguration, mockViewHistory } from '../../../../rum-core/test'
2525
import { mockProfiler } from '../../../test'
26+
import type { BrowserProfilerTrace } from '../../types'
2627
import { mockedTrace } from './test-utils/mockedTrace'
2728
import { createRumProfiler } from './profiler'
28-
import type { ProfilerTrace, RumProfilerTrace } from './types'
29+
import type { ProfilerTrace } from './types'
2930
import type { ProfilingContextManager } from './profilingContext'
3031
import { startProfilingContext } from './profilingContext'
3132
import type { ProfileEventPayload } from './transport/assembly'
@@ -56,7 +57,7 @@ describe('profiler', () => {
5657

5758
const mockProfilerTrace: ProfilerTrace = deepClone(mockedTrace)
5859

59-
const mockedRumProfilerTrace: RumProfilerTrace = Object.assign(mockProfilerTrace, {
60+
const mockedRumProfilerTrace: BrowserProfilerTrace = Object.assign(mockProfilerTrace, {
6061
startClocks: {
6162
relative: relativeNow(),
6263
timeStamp: timeStampNow(),

packages/rum/src/domain/profiling/profiler.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,13 @@ import type {
2222
ViewHistory,
2323
} from '@datadog/browser-rum-core'
2424
import { createFormDataTransport, LifeCycleEventType } from '@datadog/browser-rum-core'
25+
import type { BrowserProfilerTrace, RumViewEntry } from '../../types'
2526
import type {
26-
RumProfilerTrace,
2727
RumProfilerInstance,
2828
Profiler,
2929
RUMProfiler,
3030
RUMProfilerConfiguration,
3131
RumProfilerStoppedInstance,
32-
RumViewEntry,
3332
} from './types'
3433
import { getNumberOfSamples } from './utils/getNumberOfSamples'
3534
import type { ProfilingContextManager } from './profilingContext'
@@ -290,7 +289,7 @@ export function createRumProfiler(
290289
instance.views.push(viewEntry)
291290
}
292291

293-
function handleProfilerTrace(trace: RumProfilerTrace): void {
292+
function handleProfilerTrace(trace: BrowserProfilerTrace): void {
294293
// Find current session to assign it to the Profile.
295294
const sessionId = session.findTrackedSession()?.id
296295
const payload = assembleProfilingPayload(trace, configuration, sessionId)

packages/rum/src/domain/profiling/transport/assembly.ts

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,15 @@
11
import { buildTags, currentDrift } from '@datadog/browser-core'
22
import type { RumConfiguration } from '@datadog/browser-rum-core'
3-
import type { RumProfilerTrace } from '../types'
3+
import type { BrowserProfileEvent, BrowserProfilerTrace } from '../../../types'
44
import { buildProfileEventAttributes } from './buildProfileEventAttributes'
5-
import type { ProfileEventAttributes } from './buildProfileEventAttributes'
6-
7-
export interface ProfileEvent extends ProfileEventAttributes {
8-
attachments: string[]
9-
start: string // ISO date
10-
end: string // ISO date
11-
family: 'chrome'
12-
runtime: 'chrome'
13-
format: 'json'
14-
version: 4
15-
tags_profiler: string
16-
_dd: {
17-
clock_drift: number
18-
}
19-
}
205

216
export interface ProfileEventPayload {
22-
event: ProfileEvent
23-
'wall-time.json': RumProfilerTrace
7+
event: BrowserProfileEvent
8+
'wall-time.json': BrowserProfilerTrace
249
}
2510

2611
export function assembleProfilingPayload(
27-
profilerTrace: RumProfilerTrace,
12+
profilerTrace: BrowserProfilerTrace,
2813
configuration: RumConfiguration,
2914
sessionId: string | undefined
3015
): ProfileEventPayload {
@@ -37,15 +22,15 @@ export function assembleProfilingPayload(
3722
}
3823

3924
function buildProfileEvent(
40-
profilerTrace: RumProfilerTrace,
25+
profilerTrace: BrowserProfilerTrace,
4126
configuration: RumConfiguration,
4227
sessionId: string | undefined
43-
): ProfileEvent {
28+
): ProfileEventPayload['event'] {
4429
const tags = buildTags(configuration) // TODO: get that from the tagContext hook
4530
const profileAttributes = buildProfileEventAttributes(profilerTrace, configuration.applicationId, sessionId)
4631
const profileEventTags = buildProfileEventTags(tags)
4732

48-
const profileEvent: ProfileEvent = {
33+
const profileEvent: ProfileEventPayload['event'] = {
4934
...profileAttributes,
5035
attachments: ['wall-time.json'],
5136
start: new Date(profilerTrace.startClocks.timeStamp).toISOString(),

packages/rum/src/domain/profiling/transport/buildProfileEventAttributes.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { clocksOrigin } from '@datadog/browser-core'
22
import { RumPerformanceEntryType } from '@datadog/browser-rum-core'
33
import type { LongTaskContext } from '@datadog/browser-rum-core'
4-
import type { RumProfilerTrace, RumViewEntry } from '../types'
4+
import type { BrowserProfilerTrace, RumViewEntry } from '../../../types'
55
import { buildProfileEventAttributes, type ProfileEventAttributes } from './buildProfileEventAttributes'
66

77
describe('buildProfileEventAttributes', () => {
@@ -27,7 +27,7 @@ describe('buildProfileEventAttributes', () => {
2727
}
2828
}
2929

30-
function createMockProfilerTrace(overrides: Partial<RumProfilerTrace> = {}): RumProfilerTrace {
30+
function createMockProfilerTrace(overrides: Partial<BrowserProfilerTrace> = {}): BrowserProfilerTrace {
3131
return {
3232
startClocks: clocksOrigin(),
3333
endClocks: clocksOrigin(),

packages/rum/src/domain/profiling/transport/buildProfileEventAttributes.ts

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
1-
import type { RumProfilerTrace, RumViewEntry } from '../types'
1+
import type { BrowserProfilerTrace, RumViewEntry } from '../../../types'
22

33
export interface ProfileEventAttributes {
4-
application: { id: string }
5-
session?: { id: string }
6-
view?: { id: string[]; name: string[] }
7-
long_task?: { id: string[] }
4+
application: {
5+
id: string
6+
}
7+
session?: {
8+
id: string
9+
}
10+
view?: {
11+
id: string[]
12+
name: string[]
13+
}
14+
long_task?: {
15+
id: string[]
16+
}
817
}
918

1019
/**
@@ -16,35 +25,34 @@ export interface ProfileEventAttributes {
1625
* @returns Additional attributes.
1726
*/
1827
export function buildProfileEventAttributes(
19-
profilerTrace: RumProfilerTrace,
28+
profilerTrace: BrowserProfilerTrace,
2029
applicationId: string,
2130
sessionId: string | undefined
2231
): ProfileEventAttributes {
23-
const attributes: ProfileEventAttributes = {
24-
application: {
25-
id: applicationId,
26-
},
27-
}
28-
if (sessionId) {
29-
attributes.session = {
30-
id: sessionId,
31-
}
32-
}
33-
3432
// Extract view ids and names from the profiler trace and add them as attributes of the profile event.
3533
// This will be used to filter the profiles by @view.id and/or @view.name.
3634
const { ids, names } = extractViewIdsAndNames(profilerTrace.views)
3735

38-
if (ids.length) {
39-
attributes.view = {
40-
id: ids,
41-
name: names,
42-
}
43-
}
4436
const longTaskIds: string[] = profilerTrace.longTasks.map((longTask) => longTask.id).filter((id) => id !== undefined)
4537

46-
if (longTaskIds.length) {
47-
attributes.long_task = { id: longTaskIds }
38+
const attributes: ProfileEventAttributes = {
39+
application: {
40+
id: applicationId,
41+
},
42+
...(sessionId && {
43+
session: {
44+
id: sessionId,
45+
},
46+
}),
47+
...(ids.length && {
48+
view: {
49+
id: ids,
50+
name: names,
51+
},
52+
}),
53+
...(longTaskIds.length && {
54+
long_task: { id: longTaskIds },
55+
}),
4856
}
4957
return attributes
5058
}

packages/rum/src/domain/profiling/types/rumProfiler.types.ts

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
import type { TimeoutId, ClocksState } from '@datadog/browser-core'
22
import type { LongTaskContext } from '@datadog/browser-rum-core'
3-
import type { ProfilerTrace, Profiler } from './profilerApi.types'
4-
5-
export interface RumViewEntry {
6-
/** Detected start time of view */
7-
readonly startClocks: ClocksState
8-
/** RUM view id */
9-
readonly viewId: string
10-
/** RUM view name */
11-
readonly viewName: string | undefined
12-
}
3+
import type { RumViewEntry } from '../../../types'
4+
import type { Profiler } from './profilerApi.types'
135

146
/**
157
* Additional data recorded during profiling session
@@ -21,17 +13,6 @@ export interface RumProfilerEnrichmentData {
2113
readonly views: RumViewEntry[]
2214
}
2315

24-
export interface RumProfilerTrace extends ProfilerTrace, RumProfilerEnrichmentData {
25-
/** High resolution time when profiler trace started, relative to the profiling session's time origin */
26-
readonly startClocks: ClocksState
27-
/** High resolution time when profiler trace ended, relative to the profiling session's time origin */
28-
readonly endClocks: ClocksState
29-
/** Time origin of the profiling session */
30-
readonly clocksOrigin: ClocksState
31-
/** Sample interval in milliseconds */
32-
readonly sampleInterval: number
33-
}
34-
3516
/**
3617
* Describes profiler session state when it's stopped
3718
*/

packages/rum/src/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
export type * from './sessionReplay'
22
export * from './sessionReplayConstants'
3+
export type * from './profiling'

0 commit comments

Comments
 (0)