Skip to content

Commit

Permalink
refactor: to remove telegram token from datadog rum (#11072)
Browse files Browse the repository at this point in the history
* refactor: to remove telegram token from datadog rum

* refactor: to redact token from datadog rum

* refactor: to redact token from datadog rum

* Update packages/core/src/Utils/Datadog/index.ts

Co-authored-by: Ali(Ako) Hosseini <ali.hosseini@deriv.com>

---------

Co-authored-by: Ali(Ako) Hosseini <ali.hosseini@deriv.com>
  • Loading branch information
yaswanth-deriv and ali-hosseini-deriv committed Nov 7, 2023
1 parent cd30d5d commit 8554a83
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions packages/core/src/Utils/Datadog/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ const DATADOG_CLIENT_TOKEN = process.env.DATADOG_CLIENT_TOKEN ?? '';
const isProduction = process.env.NODE_ENV === 'production';
const isStaging = process.env.NODE_ENV === 'staging';

function getAcct1Value(url: string) {
const start = url.indexOf('acct1=') + 6; // 6 is the length of 'acct1='
const end = url.indexOf('&', start); // Find the end of the parameter value
if (end === -1) {
return url.substring(start); // If there's no '&' after acct1, get the substring from start to the end
}
return url.substring(start, end); // Get the substring between 'acct1=' and the '&'
}

let dataDogSessionSampleRate = 0;
let dataDogSessionReplaySampleRate = 0;
let dataDogVersion = '';
Expand All @@ -24,7 +33,6 @@ if (isProduction) {
dataDogSessionSampleRate = 100;
dataDogEnv = 'staging';
}

// we do it in order avoid error "application id is not configured, no RUM data will be collected"
// for test-links where application ID has not been configured and therefore RUM data will not be collected
if (isProduction || isStaging) {
Expand All @@ -43,7 +51,23 @@ if (isProduction || isStaging) {
version: dataDogVersion,
trackFrustrations: true,
enableExperimentalFeatures: ['clickmap'],
excludedActivityUrls: [/^https:\/\/api.telegram.org.*$/],
beforeSend: event => {
if (event.type === 'resource') {
event.resource.url = event.resource.url.replace(
/^https:\/\/api.telegram.org.*$/,
'telegram token=REDACTED'
);

if (event.resource.url.match(/^ https:\/\/eu.deriv.com\/ctrader-login.*$/)) {
const url = event.resource.url;
const accnt = getAcct1Value(url);
event.resource.url = event.resource.url.replace(
/^ https:\/\/eu.deriv.com\/ctrader-login.*$/,
`https://eu.deriv.com/ctrader-login?acct1=${accnt}&token1=redacted`
);
}
}
},
});

datadogRum.startSessionReplayRecording();
Expand Down

1 comment on commit 8554a83

@vercel
Copy link

@vercel vercel bot commented on 8554a83 Nov 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

deriv-app – ./

deriv-app-git-master.binary.sx
binary.sx
deriv-app.binary.sx
deriv-app.vercel.app

Please sign in to comment.