From f66058197d48adc43054a68b3494fbfe05500eb7 Mon Sep 17 00:00:00 2001 From: Bastien Caudan Date: Tue, 4 Oct 2022 16:07:35 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20add=20simulation=20label=20to=20eve?= =?UTF-8?q?nts=20during=20simulation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/domain/telemetry/telemetry.ts | 11 +++++++++-- packages/logs/src/domain/assembly.ts | 6 ++++++ packages/rum-core/src/domain/assembly.ts | 6 ++++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/packages/core/src/domain/telemetry/telemetry.ts b/packages/core/src/domain/telemetry/telemetry.ts index 5f3c122982..7363e6540d 100644 --- a/packages/core/src/domain/telemetry/telemetry.ts +++ b/packages/core/src/domain/telemetry/telemetry.ts @@ -3,7 +3,13 @@ import { ConsoleApiName } from '../../tools/display' import { toStackTraceString } from '../../tools/error' import { assign, combine, jsonStringify, performDraw, includes, startsWith, arrayFrom } from '../../tools/utils' import type { Configuration } from '../configuration' -import { getExperimentalFeatures, INTAKE_SITE_STAGING, INTAKE_SITE_US1_FED } from '../configuration' +import { + getExperimentalFeatures, + getSimulationLabel, + INTAKE_SITE_STAGING, + INTAKE_SITE_US1_FED, + isSimulationActive, +} from '../configuration' import type { StackTrace } from '../tracekit' import { computeStackTrace } from '../tracekit' import { Observable } from '../../tools/observable' @@ -82,7 +88,8 @@ export function startTelemetry(configuration: Configuration): Telemetry { telemetry: event as any, // https://github.com/microsoft/TypeScript/issues/48457 experimental_features: arrayFrom(getExperimentalFeatures()), }, - contextProvider !== undefined ? contextProvider() : {} + contextProvider !== undefined ? contextProvider() : {}, + isSimulationActive() ? { simulation_label: getSimulationLabel() } : {} ) } diff --git a/packages/logs/src/domain/assembly.ts b/packages/logs/src/domain/assembly.ts index de68c8b981..4f1a4a7c72 100644 --- a/packages/logs/src/domain/assembly.ts +++ b/packages/logs/src/domain/assembly.ts @@ -8,6 +8,8 @@ import { combine, createEventRateLimiter, getRelativeTime, + isSimulationActive, + getSimulationLabel, } from '@datadog/browser-core' import type { CommonContext } from '../rawLogsEvent.types' import type { LogsConfiguration } from './configuration' @@ -52,6 +54,10 @@ export function startLogsAssembly( messageContext ) + if (isSimulationActive()) { + log.simulation_label = getSimulationLabel() + } + if ( // Todo: [RUMF-1230] Move this check to the logger collection in the next major release !isAuthorized(rawLogsEvent.status, HandlerType.http, logger) || diff --git a/packages/rum-core/src/domain/assembly.ts b/packages/rum-core/src/domain/assembly.ts index eca99152f1..502334d8ed 100644 --- a/packages/rum-core/src/domain/assembly.ts +++ b/packages/rum-core/src/domain/assembly.ts @@ -8,6 +8,8 @@ import { display, createEventRateLimiter, canUseEventBridge, + isSimulationActive, + getSimulationLabel, } from '@datadog/browser-core' import type { RumEventDomainContext } from '../domainContext.types' import type { @@ -133,6 +135,10 @@ export function startRumAssembly( const serverRumEvent = combine(rumContext as RumContext & Context, rawRumEvent) as RumEvent & Context serverRumEvent.context = combine(commonContext.context, customerContext) + if (isSimulationActive()) { + serverRumEvent.context.simulation_label = getSimulationLabel() + } + if (!('has_replay' in serverRumEvent.session)) { ;(serverRumEvent.session as Mutable).has_replay = commonContext.hasReplay }