Skip to content

Commit

Permalink
Log study view filter endpoints go datadog (#5018)
Browse files Browse the repository at this point in the history
  • Loading branch information
alisman authored Oct 8, 2024
1 parent 1dd45af commit c0bf914
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 21 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
"@babel/plugin-transform-modules-commonjs": "^7.4.4",
"@babel/preset-env": "^7.4.4",
"@babel/preset-react": "^7.0.0",
"@datadog/browser-logs": "^5.4.0",
"@datadog/browser-logs": "^5.28.0",
"@rollup/plugin-commonjs": "^22.0.0",
"@rollup/plugin-image": "^2.1.1",
"@rollup/plugin-json": "^4.1.0",
Expand Down
90 changes: 70 additions & 20 deletions src/appBootstrapper.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { configure } from 'mobx';
import { configure, toJS } from 'mobx';
import { Provider } from 'mobx-react';
import { Router } from 'react-router-dom';
import { createBrowserHistory } from 'history';
Expand All @@ -27,7 +27,12 @@ import browser from 'bowser';
import { setNetworkListener } from './shared/lib/ajaxQuiet';
import { initializeTracking, sendToLoggly } from 'shared/lib/tracking';
import superagentCache from 'superagent-cache';
import { getBrowserWindow, onMobxPromise } from 'cbioportal-frontend-commons';
import {
getBrowserWindow,
hashString,
isWebdriver,
onMobxPromise,
} from 'cbioportal-frontend-commons';
import { AppStore } from './AppStore';
import { handleLongUrls } from 'shared/lib/handleLongUrls';
import 'shared/polyfill/canvasToBlob';
Expand All @@ -39,6 +44,7 @@ import { FeatureFlagStore } from 'shared/FeatureFlagStore';
import eventBus from 'shared/events/eventBus';
import { SiteError } from 'shared/model/appMisc';
import load from 'little-loader';
import internalClient from 'shared/api/cbioportalInternalClientInstance';

export interface ICBioWindow {
globalStores: {
Expand Down Expand Up @@ -206,6 +212,61 @@ superagent.Request.prototype.end = function(callback) {
}
});
};

function enableDataDogTracking() {
datadogLogs.init({
clientToken: 'pub9a94ebb002f105ff44d8e427b6549775',
site: 'datadoghq.com',
service: 'cbioportalinternal',
forwardErrorsToLogs: true,
sessionSampleRate: 100,
} as any);

const match = [
/filtered-samples/,
/clinical-data-bin-counts/,
/generic-assay-data-bin-counts/,
/mutated-genes/,
/molecular-profile-sample-counts/,
/cna-genes/,
/structuralvariant-genes/,
/clinical-data-counts/,
/sample-lists-counts/,
/clinical-data-density-plot/,
/clinical-data-violin-plots/,
/genomic-data-counts/,
/mutation-data-counts/,
/clinical-event-type-counts/,
/treatments\/patient-counts/,
/treatments\/sample-counts/,
/genomic-data-bin-counts/,
/clinical-event-type-counts/,
];

const oldRequest = (internalClient as any).request;
(internalClient as any).request = function(...args: any) {
try {
const url = args[1];
const data = args[2];

const studyIds = data.studyIds || data.studyViewFilter.studyIds;

if (studyIds.length < 4 && _.some(match, re => re.test(url))) {
const hash = hashString(url + JSON.stringify(toJS(data)));
datadogLogs.logger.info('study view request', {
url,
data,
hash,
});
}
} catch (ex) {
// fail silently
}

return oldRequest.apply(this, args);
};
}

//
browserWindow.routingStore = routingStore;

Expand Down Expand Up @@ -236,24 +297,6 @@ let render = (key?: number) => {
]`;
}

if (stores.appStore.serverConfig.app_name === 'mskcc-portal') {
datadogLogs.init({
clientToken: 'pub9a94ebb002f105ff44d8e427b6549775',
site: 'datadoghq.com',
service: 'cbioportalinternal',
forwardErrorsToLogs: true,
sessionSampleRate: 100,
beforeSend: (log: any) => {
switch (log.origin) {
case 'console':
return false;
default:
// let dd send log
}
},
} as any);
}

const rootNode = document.getElementById('reactRoot');

ReactDOM.render(
Expand Down Expand Up @@ -319,6 +362,13 @@ $(document).ready(async () => {

initializeAppStore(stores.appStore);

if (
stores.appStore.serverConfig.app_name === 'public-portal' &&
!isWebdriver()
) {
enableDataDogTracking();
}

await loadCustomJs();

render();
Expand Down
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1147,11 +1147,23 @@
dependencies:
"@cspotcode/source-map-consumer" "0.8.0"

"@datadog/[email protected]":
version "5.28.0"
resolved "https://registry.yarnpkg.com/@datadog/browser-core/-/browser-core-5.28.0.tgz#bd4677eeb08fcd3c98eba0600e34a2d8bc347ee2"
integrity sha512-aLYXaTkbZQIpyx+mxRGnj3Es6njoac8VhBaGr27KPuvwb/xJlBgAt5K/xdGxAPO135mdfq5evmguWuMpffE4Og==

"@datadog/[email protected]":
version "5.4.0"
resolved "https://registry.yarnpkg.com/@datadog/browser-core/-/browser-core-5.4.0.tgz#c9d55357d75a6ce25a95d235795d6b68c6f85e17"
integrity sha512-8HlKAcKXm7cJmzWQTVGnZiBs21BXkmRiknDaH9NbO6UT5JqYupXe/3zEesoX6Kxad2EzGlPVpBV816luWfqepw==

"@datadog/browser-logs@^5.28.0":
version "5.28.0"
resolved "https://registry.yarnpkg.com/@datadog/browser-logs/-/browser-logs-5.28.0.tgz#9f86067c0482d0ea01a86a185aff511252d52307"
integrity sha512-MdmgRnYgxkqHBYQ6nv9VDGLRQcqPgs68PLV6vj1uR1d36F6ZU2r6Blta8qhw3tWyopipw6y08MRuZ4XR2HLtQQ==
dependencies:
"@datadog/browser-core" "5.28.0"

"@datadog/browser-logs@^5.4.0":
version "5.4.0"
resolved "https://registry.yarnpkg.com/@datadog/browser-logs/-/browser-logs-5.4.0.tgz#fc346364b1e59acb24d400114ef74adb6f223b92"
Expand Down

0 comments on commit c0bf914

Please sign in to comment.