Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion packages/core/src/domain/telemetry/telemetryEvent.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ export type TelemetryBrowserFeaturesUsage =
/**
* Schema of mobile specific features usage
*/
export type TelemetryMobileFeaturesUsage = AddViewLoadingTime
export type TelemetryMobileFeaturesUsage = AddViewLoadingTime | TrackWebView

/**
* Schema of common properties of Telemetry events
Expand Down Expand Up @@ -640,6 +640,18 @@ export interface CommonTelemetryProperties {
* Model of the device
*/
model?: string
/**
* Number of device processors
*/
readonly processor_count?: number
/**
* Total RAM in megabytes
*/
readonly total_ram?: number
/**
* Whether the device is considered a low RAM device (Android)
*/
readonly is_low_ram_device?: boolean
[k: string]: unknown
}
/**
Expand Down Expand Up @@ -905,3 +917,10 @@ export interface AddViewLoadingTime {
overwritten: boolean
[k: string]: unknown
}
export interface TrackWebView {
/**
* trackWebView API
*/
feature: 'trackWebView'
[k: string]: unknown
}
39 changes: 18 additions & 21 deletions packages/rum-core/src/rumEvent.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ export type RumActionEvent = CommonProperties &
/**
* View properties
*/
readonly view: {
readonly view?: {
/**
* Is the action starting in the foreground (focus in browser)
*/
Expand Down Expand Up @@ -175,9 +175,6 @@ export type RumTransitionEvent = CommonProperties & {
* RUM event type
*/
readonly type: 'transition'
view: {
[k: string]: unknown
}
/**
* Stream properties
*/
Expand Down Expand Up @@ -482,7 +479,7 @@ export type RumErrorEvent = CommonProperties &
/**
* View properties
*/
readonly view: {
readonly view?: {
/**
* Is the error starting in the foreground (focus in browser)
*/
Expand All @@ -507,9 +504,6 @@ export type RumLongTaskEvent = CommonProperties &
* RUM event type
*/
readonly type: 'long_task'
view: {
[k: string]: unknown
}
/**
* Long Task properties
*/
Expand Down Expand Up @@ -634,9 +628,6 @@ export type RumResourceEvent = CommonProperties &
* RUM event type
*/
readonly type: 'resource'
view: {
[k: string]: unknown
}
/**
* Resource properties
*/
Expand Down Expand Up @@ -841,7 +832,7 @@ export type RumResourceEvent = CommonProperties &
/**
* Type of the GraphQL operation
*/
readonly operationType: 'query' | 'mutation' | 'subscription'
readonly operationType?: 'query' | 'mutation' | 'subscription'
/**
* Name of the GraphQL operation
*/
Expand Down Expand Up @@ -1329,13 +1320,10 @@ export type RumVitalEvent = RumVitalDurationEvent | RumVitalOperationStepEvent
* Schema for a duration vital event.
*/
export type RumVitalDurationEvent = RumVitalEventCommonProperties & {
view: {
[k: string]: unknown
}
/**
* Vital properties
*/
readonly vital: {
readonly vital?: {
/**
* Type of the vital.
*/
Expand Down Expand Up @@ -1381,13 +1369,10 @@ export type RumVitalEventCommonProperties = CommonProperties &
* Schema for a vital operation step event.
*/
export type RumVitalOperationStepEvent = RumVitalEventCommonProperties & {
view: {
[k: string]: unknown
}
/**
* Vital properties
*/
readonly vital: {
readonly vital?: {
/**
* Type of the vital.
*/
Expand Down Expand Up @@ -1484,7 +1469,7 @@ export interface CommonProperties {
/**
* View properties
*/
readonly view?: {
readonly view: {
/**
* UUID of the view
*/
Expand Down Expand Up @@ -1699,6 +1684,18 @@ export interface CommonProperties {
* Current screen brightness level (0.0 to 1.0).
*/
readonly brightness_level?: number
/**
* Number of device processors
*/
readonly processor_count?: number
/**
* Total RAM in megabytes
*/
readonly total_ram?: number
/**
* Whether the device is considered a low RAM device (Android)
*/
readonly is_low_ram_device?: boolean
[k: string]: unknown
}
/**
Expand Down
7 changes: 4 additions & 3 deletions packages/rum/src/domain/profiling/profiler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,10 @@ import {
mockViewHistory,
} from '../../../../rum-core/test'
import { mockProfiler } from '../../../test'
import type { BrowserProfilerTrace } from '../../types'
import { mockedTrace } from './test-utils/mockedTrace'
import { createRumProfiler } from './profiler'
import type { ProfilerTrace, RUMProfiler, RumProfilerTrace } from './types'
import type { ProfilerTrace, RUMProfiler } from './types'
import type { ProfilingContextManager } from './profilingContext'
import { startProfilingContext } from './profilingContext'
import type { ProfileEventPayload } from './transport/assembly'
Expand All @@ -48,7 +49,7 @@ describe('profiler', () => {
profiler: RUMProfiler
notifyPerformanceEntries: (entries: RumPerformanceEntry[]) => void
profilingContextManager: ProfilingContextManager
mockedRumProfilerTrace: RumProfilerTrace
mockedRumProfilerTrace: BrowserProfilerTrace
longTaskContexts: { findLongTasks: jasmine.Spy }
} {
const sessionManager = createRumSessionManagerMock().setId('session-id-1')
Expand All @@ -59,7 +60,7 @@ describe('profiler', () => {

const mockProfilerTrace: ProfilerTrace = deepClone(mockedTrace)

const mockedRumProfilerTrace: RumProfilerTrace = Object.assign(mockProfilerTrace, {
const mockedRumProfilerTrace: BrowserProfilerTrace = Object.assign(mockProfilerTrace, {
startClocks: {
relative: relativeNow(),
timeStamp: timeStampNow(),
Expand Down
5 changes: 2 additions & 3 deletions packages/rum/src/domain/profiling/profiler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@ import type {
ViewHistory,
} from '@datadog/browser-rum-core'
import { createFormDataTransport, LifeCycleEventType } from '@datadog/browser-rum-core'
import type { BrowserProfilerTrace, RumViewEntry } from '../../types'
import type {
RumProfilerTrace,
RumProfilerInstance,
Profiler,
RUMProfiler,
RUMProfilerConfiguration,
RumProfilerStoppedInstance,
RumViewEntry,
} from './types'
import { getNumberOfSamples } from './utils/getNumberOfSamples'
import type { ProfilingContextManager } from './profilingContext'
Expand Down Expand Up @@ -290,7 +289,7 @@ export function createRumProfiler(
instance.views.push(viewEntry)
}

function handleProfilerTrace(trace: RumProfilerTrace): void {
function handleProfilerTrace(trace: BrowserProfilerTrace): void {
// Find current session to assign it to the Profile.
const sessionId = session.findTrackedSession()?.id
const payload = assembleProfilingPayload(trace, configuration, sessionId)
Expand Down
29 changes: 7 additions & 22 deletions packages/rum/src/domain/profiling/transport/assembly.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,15 @@
import { buildTags, currentDrift } from '@datadog/browser-core'
import type { RumConfiguration } from '@datadog/browser-rum-core'
import type { RumProfilerTrace } from '../types'
import type { BrowserProfileEvent, BrowserProfilerTrace } from '../../../types'
import { buildProfileEventAttributes } from './buildProfileEventAttributes'
import type { ProfileEventAttributes } from './buildProfileEventAttributes'

export interface ProfileEvent extends ProfileEventAttributes {
attachments: string[]
start: string // ISO date
end: string // ISO date
family: 'chrome'
runtime: 'chrome'
format: 'json'
version: 4
tags_profiler: string
_dd: {
clock_drift: number
}
}

export interface ProfileEventPayload {
event: ProfileEvent
'wall-time.json': RumProfilerTrace
event: BrowserProfileEvent
'wall-time.json': BrowserProfilerTrace
}

export function assembleProfilingPayload(
profilerTrace: RumProfilerTrace,
profilerTrace: BrowserProfilerTrace,
configuration: RumConfiguration,
sessionId: string | undefined
): ProfileEventPayload {
Expand All @@ -37,15 +22,15 @@ export function assembleProfilingPayload(
}

function buildProfileEvent(
profilerTrace: RumProfilerTrace,
profilerTrace: BrowserProfilerTrace,
configuration: RumConfiguration,
sessionId: string | undefined
): ProfileEvent {
): ProfileEventPayload['event'] {
const tags = buildTags(configuration) // TODO: get that from the tagContext hook
const profileAttributes = buildProfileEventAttributes(profilerTrace, configuration.applicationId, sessionId)
const profileEventTags = buildProfileEventTags(tags)

const profileEvent: ProfileEvent = {
const profileEvent: ProfileEventPayload['event'] = {
...profileAttributes,
attachments: ['wall-time.json'],
start: new Date(profilerTrace.startClocks.timeStamp).toISOString(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { clocksOrigin } from '@datadog/browser-core'
import { RumPerformanceEntryType } from '@datadog/browser-rum-core'
import type { LongTaskContext } from '@datadog/browser-rum-core'
import type { RumProfilerTrace, RumViewEntry } from '../types'
import { buildProfileEventAttributes, type ProfileEventAttributes } from './buildProfileEventAttributes'
import type { BrowserProfilerTrace, RumViewEntry } from '../../../types'
import { buildProfileEventAttributes, ProfileEventAttributes } from './buildProfileEventAttributes'

describe('buildProfileEventAttributes', () => {
const applicationId = 'test-app-id'
Expand All @@ -27,7 +27,7 @@ describe('buildProfileEventAttributes', () => {
}
}

function createMockProfilerTrace(overrides: Partial<RumProfilerTrace> = {}): RumProfilerTrace {
function createMockProfilerTrace(overrides: Partial<BrowserProfilerTrace> = {}): BrowserProfilerTrace {
return {
startClocks: clocksOrigin(),
endClocks: clocksOrigin(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
import type { RumProfilerTrace, RumViewEntry } from '../types'
import type { BrowserProfilerTrace, RumViewEntry } from '../../../types'

// Type definition for the subset of BrowserProfileEvent properties that are built by this function
export interface ProfileEventAttributes {
application: { id: string }
session?: { id: string }
view?: { id: string[]; name: string[] }
long_task?: { id: string[] }
application: {
id: string
}
session?: {
id: string
}
view?: {
id: string[]
name: string[]
}
long_task?: {
id: string[]
}
}

/**
Expand All @@ -16,36 +26,36 @@ export interface ProfileEventAttributes {
* @returns Additional attributes.
*/
export function buildProfileEventAttributes(
profilerTrace: RumProfilerTrace,
profilerTrace: BrowserProfilerTrace,
applicationId: string,
sessionId: string | undefined
): ProfileEventAttributes {
const attributes: ProfileEventAttributes = {
application: {
id: applicationId,
},
}
if (sessionId) {
attributes.session = {
id: sessionId,
}
}

// Extract view ids and names from the profiler trace and add them as attributes of the profile event.
// This will be used to filter the profiles by @view.id and/or @view.name.
const { ids, names } = extractViewIdsAndNames(profilerTrace.views)

if (ids.length) {
attributes.view = {
id: ids,
name: names,
}
}
const longTaskIds: string[] = profilerTrace.longTasks.map((longTask) => longTask.id).filter((id) => id !== undefined)

if (longTaskIds.length) {
attributes.long_task = { id: longTaskIds }
const attributes: ProfileEventAttributes = {
application: {
id: applicationId,
},
...(sessionId && {
session: {
id: sessionId,
},
}),
...(ids.length && {
view: {
id: ids,
name: names,
},
}),
...(longTaskIds.length && {
long_task: { id: longTaskIds },
}),
}

return attributes
}

Expand Down
Loading