From 23ac3e75cfd6871abdee12ea396f6965e41e6ec4 Mon Sep 17 00:00:00 2001 From: "Ali(Ako) Hosseini" Date: Wed, 10 May 2023 17:36:40 +0800 Subject: [PATCH] feat: add ability to track staging and production with different service names (#8537) --- packages/core/build/constants.js | 1 + packages/core/src/Utils/Datadog/index.ts | 35 ++++++++++++++++++------ 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/packages/core/build/constants.js b/packages/core/build/constants.js index 0f5bd8ff1614..581b57465dbe 100644 --- a/packages/core/build/constants.js +++ b/packages/core/build/constants.js @@ -135,6 +135,7 @@ const plugins = ({ base, is_test_env }) => { ), 'process.env.DATADOG_SESSION_SAMPLE_RATE': JSON.stringify(process.env.DATADOG_SESSION_SAMPLE_RATE), 'process.env.CIRCLE_TAG': JSON.stringify(process.env.CIRCLE_TAG), + 'process.env.CIRCLE_JOB': JSON.stringify(process.env.CIRCLE_JOB), }), new CleanWebpackPlugin(), new CopyPlugin(copyConfig(base)), diff --git a/packages/core/src/Utils/Datadog/index.ts b/packages/core/src/Utils/Datadog/index.ts index 945809e6aa2d..ba770d85ad1c 100644 --- a/packages/core/src/Utils/Datadog/index.ts +++ b/packages/core/src/Utils/Datadog/index.ts @@ -1,24 +1,41 @@ import { datadogRum } from '@datadog/browser-rum'; +import { formatDate, formatTime } from '@deriv/shared'; const DATADOG_APP_ID = process.env.DATADOG_APPLICATION_ID ?? ''; const DATADOG_CLIENT_TOKEN = process.env.DATADOG_CLIENT_TOKEN ?? ''; -const DATADOG_SESSION_SAMPLE_RATE = process.env.DATADOG_SESSION_SAMPLE_RATE ?? 10; -const DATADOG_SESSION_REPLAY_SAMPLE_RATE = process.env.DATADOG_SESSION_REPLAY_SAMPLE_RATE ?? 1; -const CIRCLE_TAG = process.env.CIRCLE_TAG ?? 'NO_VERSION'; +const isProduction = process.env.CIRCLE_JOB === 'release_production'; +const isStaging = process.env.CIRCLE_JOB === 'release_staging'; + +let dataDogSessionSampleRate = 0; +let dataDogSessionReplaySampleRate = 0; +let dataDogVersion = ''; +let serviceName = ''; + +if (isProduction) { + serviceName = 'app.deriv.com'; + dataDogVersion = `deriv-app-${process.env.CIRCLE_TAG}`; + dataDogSessionReplaySampleRate = +process.env.DATADOG_SESSION_REPLAY_SAMPLE_RATE! ?? 1; + dataDogSessionSampleRate = +process.env.DATADOG_SESSION_SAMPLE_RATE! ?? 10; +} else if (isStaging) { + serviceName = 'staging-app.deriv.com'; + dataDogVersion = `deriv-app-staging-v${formatDate(new Date(), 'YYYYMMDD')}-${formatTime(Date.now(), 'HH:mm')}`; + dataDogSessionReplaySampleRate = 100; + dataDogSessionSampleRate = 100; +} datadogRum.init({ - applicationId: DATADOG_APP_ID, - clientToken: DATADOG_CLIENT_TOKEN, + applicationId: isStaging || isProduction ? DATADOG_APP_ID : '', + clientToken: isStaging || isProduction ? DATADOG_CLIENT_TOKEN : '', site: 'datadoghq.com', - service: 'app.deriv.com', + service: serviceName, env: 'production', - sessionSampleRate: +DATADOG_SESSION_SAMPLE_RATE, - sessionReplaySampleRate: +DATADOG_SESSION_REPLAY_SAMPLE_RATE, + sessionSampleRate: dataDogSessionSampleRate, + sessionReplaySampleRate: dataDogSessionReplaySampleRate, trackUserInteractions: true, trackResources: true, trackLongTasks: true, defaultPrivacyLevel: 'mask-user-input', - version: `deriv-app-${CIRCLE_TAG}`, + version: dataDogVersion, trackFrustrations: true, enableExperimentalFeatures: ['clickmap'], });