Skip to content

Commit

Permalink
feat: add ability to track staging and production with different serv…
Browse files Browse the repository at this point in the history
…ice names
  • Loading branch information
ali-hosseini-deriv committed May 10, 2023
1 parent b51a956 commit 9c911fa
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
1 change: 1 addition & 0 deletions packages/core/build/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
35 changes: 26 additions & 9 deletions packages/core/src/Utils/Datadog/index.ts
Original file line number Diff line number Diff line change
@@ -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'],
});
Expand Down

0 comments on commit 9c911fa

Please sign in to comment.