From c0bf914f189335e3f781ce6adbcb80b201d3787b Mon Sep 17 00:00:00 2001 From: alisman Date: Tue, 8 Oct 2024 09:52:55 -0400 Subject: [PATCH] Log study view filter endpoints go datadog (#5018) --- package.json | 2 +- src/appBootstrapper.tsx | 90 ++++++++++++++++++++++++++++++++--------- yarn.lock | 12 ++++++ 3 files changed, 83 insertions(+), 21 deletions(-) diff --git a/package.json b/package.json index 70907bc750a..5a28b4356ae 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/appBootstrapper.tsx b/src/appBootstrapper.tsx index d36088736a4..59021cc3b85 100755 --- a/src/appBootstrapper.tsx +++ b/src/appBootstrapper.tsx @@ -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'; @@ -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'; @@ -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: { @@ -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; @@ -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( @@ -319,6 +362,13 @@ $(document).ready(async () => { initializeAppStore(stores.appStore); + if ( + stores.appStore.serverConfig.app_name === 'public-portal' && + !isWebdriver() + ) { + enableDataDogTracking(); + } + await loadCustomJs(); render(); diff --git a/yarn.lock b/yarn.lock index 840732ddb91..58b143d0a42 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1147,11 +1147,23 @@ dependencies: "@cspotcode/source-map-consumer" "0.8.0" +"@datadog/browser-core@5.28.0": + 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/browser-core@5.4.0": 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"