Skip to content

Commit

Permalink
✨ add id on rum events (#873)
Browse files Browse the repository at this point in the history
* ✨ generate event types with new rum-event-format

* add id to all RUM event actions

* Add id to all RUM event error

* Add id to all RUM event long task

* Add id to all RUM event resource

* Add id to all RUM event view

* ✅ add ids to test fixures

* Update action context test with required id

* 👌 Remove id from RawRumViewEvent

* 👌 remove the unnecessary resource.id

* 👌 Remove view id from test viewCollection

* Make all RUM events ids required

* Remove unnecessary typescript type assertion

* Update rum-event-format to master

* ✅  Action context not override rum event action id

* 👌 Regenerate rum event types with latest format
  • Loading branch information
amortemousque authored May 31, 2021
1 parent e241d8d commit cbc6064
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/rum-core/src/domain/assembly.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ describe('rum assembly', () => {
rawRumEvent: createRawRumEvent(RumEventType.ACTION),
startTime: 0 as RelativeTime,
})
expect((serverRumEvents[0] as RumActionEvent).action.id).not.toBeDefined()
expect((serverRumEvents[0] as RumActionEvent).action.id).not.toEqual('7890')
serverRumEvents = []
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ describe('actionCollection', () => {
expect(rawRumEvents[0].startTime).toBe(1234)
expect(rawRumEvents[0].rawRumEvent).toEqual({
action: {
id: jasmine.any(String),
target: {
name: 'foo',
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { combine, Configuration, toServerDuration } from '@datadog/browser-core'
import { combine, Configuration, toServerDuration, generateUUID } from '@datadog/browser-core'
import { ActionType, CommonContext, RumEventType } from '../../../rawRumEvent.types'
import { LifeCycle, LifeCycleEventType } from '../../lifeCycle'
import { AutoAction, CustomAction, trackActions } from './trackActions'
Expand Down Expand Up @@ -44,6 +44,7 @@ function processAction(action: AutoAction | CustomAction) {
const actionEvent = combine(
{
action: {
id: generateUUID(),
target: {
name: action.name,
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ describe('error collection', () => {
rawRumEvent: {
date: jasmine.any(Number),
error: {
id: jasmine.any(String),
message: 'foo',
resource: undefined,
source: ErrorSource.CUSTOM,
Expand Down Expand Up @@ -116,6 +117,7 @@ describe('error collection', () => {
expect(rawRumEvents[0].rawRumEvent).toEqual({
date: jasmine.any(Number),
error: {
id: jasmine.any(String),
message: 'hello',
resource: {
method: 'GET',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
RawError,
startAutomaticErrorCollection,
ClocksState,
generateUUID,
} from '@datadog/browser-core'
import { CommonContext, RawRumErrorEvent, RumEventType } from '../../../rawRumEvent.types'
import { LifeCycle, LifeCycleEventType } from '../../lifeCycle'
Expand Down Expand Up @@ -60,6 +61,7 @@ function processError(error: RawError) {
const rawRumEvent: RawRumErrorEvent = {
date: error.startClocks.timeStamp,
error: {
id: generateUUID(),
message: error.message,
resource: error.resource
? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ describe('long task collection', () => {
expect(rawRumEvents[0].rawRumEvent).toEqual({
date: jasmine.any(Number),
long_task: {
id: jasmine.any(String),
duration: (100 * 1e6) as ServerDuration,
},
type: RumEventType.LONG_TASK,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { toServerDuration, relativeToClocks } from '@datadog/browser-core'
import { toServerDuration, relativeToClocks, generateUUID } from '@datadog/browser-core'
import { RawRumLongTaskEvent, RumEventType } from '../../../rawRumEvent.types'
import { LifeCycle, LifeCycleEventType } from '../../lifeCycle'

Expand All @@ -11,6 +11,7 @@ export function startLongTaskCollection(lifeCycle: LifeCycle) {
const rawRumEvent: RawRumLongTaskEvent = {
date: startClocks.timeStamp,
long_task: {
id: generateUUID(),
duration: toServerDuration(entry.duration),
},
type: RumEventType.LONG_TASK,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ describe('resourceCollection', () => {
expect(rawRumEvents[0].rawRumEvent).toEqual({
date: (jasmine.any(Number) as unknown) as TimeStamp,
resource: {
id: jasmine.any(String),
duration: (100 * 1e6) as ServerDuration,
size: undefined,
type: ResourceType.OTHER,
Expand Down Expand Up @@ -72,6 +73,7 @@ describe('resourceCollection', () => {
expect(rawRumEvents[0].rawRumEvent).toEqual({
date: jasmine.any(Number),
resource: {
id: jasmine.any(String),
duration: (100 * 1e6) as ServerDuration,
method: 'GET',
status_code: 200,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ function processRequest(request: RequestCompleteEvent) {
{
date: startClocks.timeStamp,
resource: {
id: generateUUID(),
type,
duration: toServerDuration(request.duration),
method: request.method,
Expand All @@ -71,6 +72,7 @@ function processResourceEntry(entry: RumPerformanceResourceTiming) {
{
date: startClocks.timeStamp,
resource: {
id: generateUUID(),
type,
url: entry.name,
},
Expand Down Expand Up @@ -102,7 +104,6 @@ function computeRequestTracingInfo(request: RequestCompleteEvent) {
span_id: request.spanId!.toDecimalString(),
trace_id: request.traceId!.toDecimalString(),
},
resource: { id: generateUUID() },
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe('viewCollection', () => {
resourceCount: 10,
userActionCount: 10,
},
id: 'xxx',
id: 'aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee',
name: undefined,
isActive: false,
hasReplay: false,
Expand Down
6 changes: 4 additions & 2 deletions packages/rum-core/src/rawRumEvent.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface RawRumResourceEvent {
type: RumEventType.RESOURCE
resource: {
type: ResourceType
id?: string // only for traced requests
id: string
duration: ServerDuration
url: string
method?: string
Expand Down Expand Up @@ -46,6 +46,7 @@ export interface RawRumErrorEvent {
status_code: number
method: string
}
id: string
type?: string
stack?: string
source: ErrorSource
Expand Down Expand Up @@ -104,6 +105,7 @@ export interface RawRumLongTaskEvent {
date: TimeStamp
type: RumEventType.LONG_TASK
long_task: {
id: string
duration: ServerDuration
}
}
Expand All @@ -112,7 +114,7 @@ export interface RawRumActionEvent {
date: TimeStamp
type: RumEventType.ACTION
action: {
id?: string
id: string
type: ActionType
loading_time?: ServerDuration
error?: Count
Expand Down
6 changes: 6 additions & 0 deletions packages/rum-core/test/fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
Context,
Duration,
ErrorSource,
generateUUID,
RelativeTime,
ResourceType,
ServerDuration,
Expand All @@ -18,6 +19,7 @@ export function createRawRumEvent(type: RumEventType, overrides?: Context): RawR
{
type,
action: {
id: generateUUID(),
target: {
name: 'target',
},
Expand All @@ -33,6 +35,7 @@ export function createRawRumEvent(type: RumEventType, overrides?: Context): RawR
type,
date: 0 as TimeStamp,
long_task: {
id: generateUUID(),
duration: 0 as ServerDuration,
},
},
Expand All @@ -44,6 +47,7 @@ export function createRawRumEvent(type: RumEventType, overrides?: Context): RawR
type,
date: 0 as TimeStamp,
error: {
id: generateUUID(),
message: 'oh snap',
source: ErrorSource.SOURCE,
},
Expand All @@ -56,6 +60,7 @@ export function createRawRumEvent(type: RumEventType, overrides?: Context): RawR
type,
date: 0 as TimeStamp,
resource: {
id: generateUUID(),
duration: 0 as ServerDuration,
type: ResourceType.OTHER,
url: 'http://foo.bar',
Expand All @@ -72,6 +77,7 @@ export function createRawRumEvent(type: RumEventType, overrides?: Context): RawR
},
date: 0 as TimeStamp,
view: {
id: generateUUID(),
action: { count: 0 },
error: { count: 0 },
is_active: true,
Expand Down
2 changes: 1 addition & 1 deletion rum-events-format
Submodule rum-events-format updated 1 files
+13 −2 README.md

0 comments on commit cbc6064

Please sign in to comment.