Skip to content

Commit

Permalink
[RUMF-1068] Forward browser_sdk_version to mobile (#1162)
Browse files Browse the repository at this point in the history
* Add browser_sdk_version inside _dd
  • Loading branch information
amortemousque authored Dec 6, 2021
1 parent a7e7de1 commit edad30f
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 3 deletions.
28 changes: 27 additions & 1 deletion packages/rum-core/src/domain/assembly.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
import { ErrorSource, ONE_MINUTE, RawError, RelativeTime, display } from '@datadog/browser-core'
import {
ErrorSource,
ONE_MINUTE,
RawError,
RelativeTime,
display,
updateExperimentalFeatures,
resetExperimentalFeatures,
} from '@datadog/browser-core'
import { createRumSessionMock } from '../../test/mockRumSession'
import { createRawRumEvent } from '../../test/fixtures'
import {
Expand All @@ -10,6 +18,7 @@ import {
import { RumEventDomainContext } from '../domainContext.types'
import { CommonContext, RawRumActionEvent, RawRumErrorEvent, RawRumEvent, RumEventType } from '../rawRumEvent.types'
import { RumActionEvent, RumErrorEvent, RumEvent } from '../rumEvent.types'
import { initEventBridgeStub, deleteEventBridgeStub } from '../../../core/test/specHelper'
import { startRumAssembly } from './assembly'
import { LifeCycle, LifeCycleEventType, RawRumEventCollectedData } from './lifeCycle'
import { RumSessionPlan } from './rumSession'
Expand Down Expand Up @@ -60,6 +69,8 @@ describe('rum assembly', () => {
})

afterEach(() => {
resetExperimentalFeatures()
deleteEventBridgeStub()
setupBuilder.cleanup()
cleanupSyntheticsWorkerValues()
})
Expand Down Expand Up @@ -566,6 +577,21 @@ describe('rum assembly', () => {
})
})

describe('if event bridge detected', () => {
it('includes the browser sdk version', () => {
const { lifeCycle } = setupBuilder.build()
notifyRawRumEvent(lifeCycle, { rawRumEvent: createRawRumEvent(RumEventType.VIEW) })

updateExperimentalFeatures(['event-bridge'])
initEventBridgeStub()

notifyRawRumEvent(lifeCycle, { rawRumEvent: createRawRumEvent(RumEventType.VIEW) })

expect(serverRumEvents[0]._dd.browser_sdk_version).not.toBeDefined()
expect(serverRumEvents[1]._dd.browser_sdk_version).toBeDefined()
})
})

describe('error events limitation', () => {
const notifiedRawErrors: RawError[] = []

Expand Down
4 changes: 4 additions & 0 deletions packages/rum-core/src/domain/assembly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
RawError,
createEventRateLimiter,
EventRateLimiter,
canUseEventBridge,
} from '@datadog/browser-core'
import { RumEventDomainContext } from '../domainContext.types'
import {
Expand All @@ -24,6 +25,7 @@ import {
User,
} from '../rawRumEvent.types'
import { RumEvent } from '../rumEvent.types'
import { buildEnv } from '../boot/buildEnv'
import { getSyntheticsContext } from './syntheticsContext'
import { LifeCycle, LifeCycleEventType } from './lifeCycle'
import { ParentContexts } from './parentContexts'
Expand Down Expand Up @@ -89,6 +91,7 @@ export function startRumAssembly(
session: {
plan: session.hasReplayPlan() ? RumSessionPlan.REPLAY : RumSessionPlan.LITE,
},
browser_sdk_version: canUseEventBridge() ? buildEnv.sdkVersion : undefined,
},
application: {
id: applicationId,
Expand All @@ -113,6 +116,7 @@ export function startRumAssembly(
if (!isEmptyObject(commonContext.user)) {
;(serverRumEvent.usr as Mutable<RumEvent['usr']>) = commonContext.user as User & Context
}

if (shouldSend(serverRumEvent, configuration.beforeSend, domainContext, eventRateLimiters)) {
if (isEmptyObject(serverRumEvent.context)) {
delete serverRumEvent.context
Expand Down
1 change: 1 addition & 0 deletions packages/rum-core/src/rawRumEvent.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ export interface RumContext {
session: {
plan: RumSessionPlan
}
browser_sdk_version?: string
}
}

Expand Down
25 changes: 24 additions & 1 deletion packages/rum-core/src/rumEvent.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,10 @@ export type RumErrorEvent = CommonProperties & {
* Handling call stack
*/
readonly handling_stack?: string
/**
* Source type of the error (the language or platform impacting the error stacktrace format)
*/
readonly source_type?: 'android' | 'browser' | 'ios' | 'react-native'
/**
* Resource properties of the error
*/
Expand Down Expand Up @@ -270,7 +274,18 @@ export type RumResourceEvent = CommonProperties & {
/**
* Resource type
*/
readonly type: 'document' | 'xhr' | 'beacon' | 'fetch' | 'css' | 'js' | 'image' | 'font' | 'media' | 'other'
readonly type:
| 'document'
| 'xhr'
| 'beacon'
| 'fetch'
| 'css'
| 'js'
| 'image'
| 'font'
| 'media'
| 'other'
| 'native'
/**
* HTTP method of the resource
*/
Expand Down Expand Up @@ -760,6 +775,10 @@ export interface CommonProperties {
* The identifier of the current Synthetics test results
*/
readonly result_id: string
/**
* Whether the event comes from a SDK instance injected by Synthetics
*/
readonly injected?: boolean
[k: string]: unknown
}
/**
Expand All @@ -780,6 +799,10 @@ export interface CommonProperties {
plan: 1 | 2
[k: string]: unknown
}
/**
* Browser SDK version
*/
readonly browser_sdk_version?: string
[k: string]: unknown
}
/**
Expand Down
2 changes: 1 addition & 1 deletion rum-events-format

0 comments on commit edad30f

Please sign in to comment.