From edad30f556864f3ed4640fabc2f71f8fd7ffb455 Mon Sep 17 00:00:00 2001 From: Aymeric Date: Mon, 6 Dec 2021 12:08:24 +0100 Subject: [PATCH] [RUMF-1068] Forward browser_sdk_version to mobile (#1162) * Add browser_sdk_version inside _dd --- packages/rum-core/src/domain/assembly.spec.ts | 28 ++++++++++++++++++- packages/rum-core/src/domain/assembly.ts | 4 +++ packages/rum-core/src/rawRumEvent.types.ts | 1 + packages/rum-core/src/rumEvent.types.ts | 25 ++++++++++++++++- rum-events-format | 2 +- 5 files changed, 57 insertions(+), 3 deletions(-) diff --git a/packages/rum-core/src/domain/assembly.spec.ts b/packages/rum-core/src/domain/assembly.spec.ts index d4b116cfd4..d04cdb36a4 100644 --- a/packages/rum-core/src/domain/assembly.spec.ts +++ b/packages/rum-core/src/domain/assembly.spec.ts @@ -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 { @@ -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' @@ -60,6 +69,8 @@ describe('rum assembly', () => { }) afterEach(() => { + resetExperimentalFeatures() + deleteEventBridgeStub() setupBuilder.cleanup() cleanupSyntheticsWorkerValues() }) @@ -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[] = [] diff --git a/packages/rum-core/src/domain/assembly.ts b/packages/rum-core/src/domain/assembly.ts index 6d88bac094..960be29642 100644 --- a/packages/rum-core/src/domain/assembly.ts +++ b/packages/rum-core/src/domain/assembly.ts @@ -11,6 +11,7 @@ import { RawError, createEventRateLimiter, EventRateLimiter, + canUseEventBridge, } from '@datadog/browser-core' import { RumEventDomainContext } from '../domainContext.types' import { @@ -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' @@ -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, @@ -113,6 +116,7 @@ export function startRumAssembly( if (!isEmptyObject(commonContext.user)) { ;(serverRumEvent.usr as Mutable) = commonContext.user as User & Context } + if (shouldSend(serverRumEvent, configuration.beforeSend, domainContext, eventRateLimiters)) { if (isEmptyObject(serverRumEvent.context)) { delete serverRumEvent.context diff --git a/packages/rum-core/src/rawRumEvent.types.ts b/packages/rum-core/src/rawRumEvent.types.ts index 7891ae09b7..e9ee101e80 100644 --- a/packages/rum-core/src/rawRumEvent.types.ts +++ b/packages/rum-core/src/rawRumEvent.types.ts @@ -188,6 +188,7 @@ export interface RumContext { session: { plan: RumSessionPlan } + browser_sdk_version?: string } } diff --git a/packages/rum-core/src/rumEvent.types.ts b/packages/rum-core/src/rumEvent.types.ts index f5a35add65..e50f48bfd7 100644 --- a/packages/rum-core/src/rumEvent.types.ts +++ b/packages/rum-core/src/rumEvent.types.ts @@ -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 */ @@ -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 */ @@ -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 } /** @@ -780,6 +799,10 @@ export interface CommonProperties { plan: 1 | 2 [k: string]: unknown } + /** + * Browser SDK version + */ + readonly browser_sdk_version?: string [k: string]: unknown } /** diff --git a/rum-events-format b/rum-events-format index cdf9a70e6b..00fa446544 160000 --- a/rum-events-format +++ b/rum-events-format @@ -1 +1 @@ -Subproject commit cdf9a70e6be9cfec5e9524c58abfe79a9fea1f64 +Subproject commit 00fa4465444e122e9c904f5531a701eeca4ceb0e