Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

⚗️[RUM-2889] Bootstrap custom vital APIs #2591

Merged
merged 8 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {
RumLongTaskEvent,
RumResourceEvent,
RumViewEvent,
RumVitalEvent,
} from '../../../../../../packages/rum-core/src/rumEvent.types'
import type { SdkEvent } from '../../../sdkEvent'
import { isTelemetryEvent, isLogEvent, isRumEvent } from '../../../sdkEvent'
Expand All @@ -32,6 +33,7 @@ const RUM_EVENT_TYPE_COLOR = {
view: 'blue',
resource: 'cyan',
telemetry: 'teal',
vital: 'orange',
}

const LOG_STATUS_COLOR = {
Expand Down Expand Up @@ -260,6 +262,8 @@ export const EventDescription = React.memo(({ event }: { event: SdkEvent }) => {
return <ResourceDescription event={event} />
case 'action':
return <ActionDescription event={event} />
case 'vital':
return <VitalDescription event={event} />
}
} else if (isLogEvent(event)) {
return <LogDescription event={event} />
Expand Down Expand Up @@ -322,6 +326,17 @@ function LongTaskDescription({ event }: { event: RumLongTaskEvent }) {
)
}

function VitalDescription({ event }: { event: RumVitalEvent }) {
const vitalName = Object.keys(event.vital.custom!)[0]
const vitalValue = event.vital.custom![vitalName]
return (
<>
Custom <Emphasis>{event.vital.type}</Emphasis> vital: <Emphasis>{vitalName}</Emphasis> of{' '}
<Emphasis>{vitalValue}</Emphasis>
</>
)
}

function ErrorDescription({ event }: { event: RumErrorEvent }) {
return (
<>
Expand Down
1 change: 1 addition & 0 deletions packages/rum-core/src/domain/assembly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ export function startRumAssembly(
VIEW_MODIFIABLE_FIELD_PATHS
),
[RumEventType.LONG_TASK]: assign({}, USER_CUSTOMIZABLE_FIELD_PATHS, VIEW_MODIFIABLE_FIELD_PATHS),
[RumEventType.VITAL]: assign({}, USER_CUSTOMIZABLE_FIELD_PATHS, VIEW_MODIFIABLE_FIELD_PATHS),
}
const eventRateLimiters = {
[RumEventType.ERROR]: createEventRateLimiter(
Expand Down
11 changes: 6 additions & 5 deletions packages/rum-core/src/domain/trackEventCounts.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,12 @@ describe('trackEventCounts', () => {
notifyCollectedRawRumEvent({ type: RumEventType.LONG_TASK })
expect(eventCounts.longTaskCount).toBe(1)
})

it("doesn't track views", () => {
const { eventCounts } = trackEventCounts({ lifeCycle, isChildEvent: () => true })
notifyCollectedRawRumEvent({ type: RumEventType.VIEW })
expect(objectValues(eventCounts as unknown as { [key: string]: number }).every((value) => value === 0)).toBe(true)
;[RumEventType.VIEW, RumEventType.VITAL].forEach((eventType) => {
bcaudan marked this conversation as resolved.
Show resolved Hide resolved
it(`doesn't track ${eventType} events`, () => {
const { eventCounts } = trackEventCounts({ lifeCycle, isChildEvent: () => true })
notifyCollectedRawRumEvent({ type: eventType })
expect(objectValues(eventCounts as unknown as { [key: string]: number }).every((value) => value === 0)).toBe(true)
})
})

it('tracks actions', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/rum-core/src/domain/trackEventCounts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export function trackEventCounts({
}

const subscription = lifeCycle.subscribe(LifeCycleEventType.RUM_EVENT_COLLECTED, (event): void => {
if (event.type === 'view' || !isChildEvent(event)) {
if (event.type === 'view' || event.type === 'vital' || !isChildEvent(event)) {
return
}
switch (event.type) {
Expand Down
6 changes: 5 additions & 1 deletion packages/rum-core/src/domainContext.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ export type RumEventDomainContext<T extends RumEventType = any> = T extends RumE
? RumErrorEventDomainContext
: T extends RumEventType.LONG_TASK
? RumLongTaskEventDomainContext
: never
: T extends RumEventType.VITAL
? RumVitalEventDomainContext
: never

export interface RumViewEventDomainContext {
location: Readonly<Location>
Expand Down Expand Up @@ -48,3 +50,5 @@ export interface RumErrorEventDomainContext {
export interface RumLongTaskEventDomainContext {
performanceEntry: PerformanceEntry
}

export interface RumVitalEventDomainContext {}
1 change: 1 addition & 0 deletions packages/rum-core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export {
RumViewEvent,
RumResourceEvent,
RumLongTaskEvent,
RumVitalEvent,
} from './rumEvent.types'
export {
RumLongTaskEventDomainContext,
Expand Down
18 changes: 18 additions & 0 deletions packages/rum-core/src/rawRumEvent.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const enum RumEventType {
LONG_TASK = 'long_task',
VIEW = 'view',
RESOURCE = 'resource',
VITAL = 'vital',
}

export interface RawRumResourceEvent {
Expand Down Expand Up @@ -215,12 +216,29 @@ export const enum FrustrationType {
DEAD_CLICK = 'dead_click',
}

export interface RawRumVitalEvent {
date: TimeStamp
type: RumEventType.VITAL
vital: {
id: string
type: VitalType
custom: {
[key: string]: number
}
}
}

export const enum VitalType {
DURATION = 'duration',
}

export type RawRumEvent =
| RawRumErrorEvent
| RawRumResourceEvent
| RawRumViewEvent
| RawRumLongTaskEvent
| RawRumActionEvent
| RawRumVitalEvent

export interface RumContext {
date: TimeStamp
Expand Down
19 changes: 17 additions & 2 deletions packages/rum-core/test/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
relativeNow,
ResourceType,
} from '@datadog/browser-core'
import { RumPerformanceEntryType } from '../src/browser/performanceCollection'
import type {
RumFirstInputTiming,
RumLargestContentfulPaintTiming,
Expand All @@ -19,8 +18,9 @@ import type {
RumPerformancePaintTiming,
RumPerformanceResourceTiming,
} from '../src/browser/performanceCollection'
import { RumPerformanceEntryType } from '../src/browser/performanceCollection'
import type { RawRumEvent } from '../src/rawRumEvent.types'
import { ActionType, RumEventType, ViewLoadingType } from '../src/rawRumEvent.types'
import { VitalType, ActionType, RumEventType, ViewLoadingType } from '../src/rawRumEvent.types'

export function createRawRumEvent(type: RumEventType, overrides?: Context): RawRumEvent {
switch (type) {
Expand All @@ -39,6 +39,21 @@ export function createRawRumEvent(type: RumEventType, overrides?: Context): RawR
},
overrides
)
case RumEventType.VITAL:
return combine(
{
type,
date: 0 as TimeStamp,
vital: {
id: generateUUID(),
type: VitalType.DURATION,
custom: {
timing: 0 as ServerDuration,
},
},
},
overrides
)
case RumEventType.LONG_TASK:
return combine(
{
Expand Down
1 change: 1 addition & 0 deletions packages/rum/src/entries/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export {
RumLongTaskEvent,
RumResourceEvent,
RumViewEvent,
RumVitalEvent,
// Events context
RumEventDomainContext,
RumViewEventDomainContext,
Expand Down