diff --git a/src/api-base.js b/src/api-base.js index fd6207543..6fa2ee9bb 100644 --- a/src/api-base.js +++ b/src/api-base.js @@ -8,8 +8,8 @@ import { setConfigAppID, } from '@storage'; import DerivAPIBasic from '@deriv/deriv-api/dist/DerivAPIBasic'; -import { observer as globalObserver } from '@utilities/observer'; import APIMiddleware from './api-middleware'; +import { observer as globalObserver } from '@utilities/observer'; const socket_url = `wss://${getServerAddressFallback()}/websockets/v3?app_id=${getAppIdFallback()}&l=${getLanguage().toUpperCase()}&brand=deriv`; diff --git a/src/api-middleware.js b/src/api-middleware.js index 8471350f7..00d7b4cc4 100644 --- a/src/api-middleware.js +++ b/src/api-middleware.js @@ -1,37 +1,3 @@ -import { datadogLogs } from '@datadog/browser-logs'; -import { formatDate } from './utilities/utility-functions'; - -const DATADOG_CLIENT_LOGS_TOKEN = process.env.DATADOG_CLIENT_LOGS_TOKEN ?? ''; -const isProduction = process.env.NODE_ENV === 'production'; -const isStaging = process.env.NODE_ENV === 'staging'; -let dataDogSessionSampleRate = 0; - -dataDogSessionSampleRate = process.env.DATADOG_LOGS_SESSION_SAMPLE_RATE - ? +process.env.DATADOG_LOGS_SESSION_SAMPLE_RATE - : 1; -let dataDogVersion = ''; -let dataDogEnv = ''; - -if (isProduction) { - dataDogVersion = `binary-bot-${process.env.REF_NAME}`; - dataDogEnv = 'production'; -} else if (isStaging) { - dataDogVersion = `binary-bot-staging-v${formatDate(new Date())}`; - dataDogEnv = 'staging'; -} - -if (DATADOG_CLIENT_LOGS_TOKEN) { - datadogLogs.init({ - clientToken: DATADOG_CLIENT_LOGS_TOKEN, - site: 'datadoghq.com', - forwardErrorsToLogs: false, - service: 'BinaryBot', - sessionSampleRate: dataDogSessionSampleRate, - version: dataDogVersion, - env: dataDogEnv, - }); -} - export const REQUESTS = [ 'active_symbols', 'authorize', @@ -39,18 +5,19 @@ export const REQUESTS = [ 'buy', 'proposal', 'proposal_open_contract', + 'run-proposal', 'transaction', 'ticks_history', - 'history', + 'history' ]; class APIMiddleware { constructor(config) { this.config = config; + this.debounced_calls = {}; this.addGlobalMethod(); } - /* eslint-disable class-methods-use-this */ getRequestType = request => { let req_type; REQUESTS.forEach(type => { @@ -60,31 +27,27 @@ class APIMiddleware { return req_type; }; - /* eslint-disable class-methods-use-this */ - log = (measures = [], is_bot_running) => { - if (measures && measures.length) { - measures.forEach(measure => { - datadogLogs.logger.info(measure.name, { - name: measure.name, - startTime: measure.startTimeDate, - duration: measure.duration, - detail: measure.detail, - isBotRunning: is_bot_running, - }); - }); - } - }; - - /* eslint-disable class-methods-use-this */ defineMeasure = res_type => { if (res_type) { let measure; + if (res_type === 'proposal') { + performance.mark('first_proposal_end'); + if (performance.getEntriesByName('bot-start', 'mark').length) { + measure = performance.measure('run-proposal', 'bot-start', 'first_proposal_end'); + performance.clearMarks('bot-start'); + console.table('bot-first-run', measure.duration) + } + } if (res_type === 'history') { performance.mark('ticks_history_end'); measure = performance.measure('ticks_history', 'ticks_history_start', 'ticks_history_end'); + console.table('ticks_history', measure.duration) } else { performance.mark(`${res_type}_end`); measure = performance.measure(`${res_type}`, `${res_type}_start`, `${res_type}_end`); + if (res_type === 'proposal') { + console.table('proposal', measure.duration) + } } return (measure.startTimeDate = new Date(Date.now() - measure.startTime)); } @@ -94,26 +57,19 @@ class APIMiddleware { sendIsCalled = ({ response_promise, args: [request] }) => { const req_type = this.getRequestType(request); if (req_type) performance.mark(`${req_type}_start`); - response_promise - .then(res => { - const res_type = this.getRequestType(res); - if (res_type) { - this.defineMeasure(res_type); - } - }) - .catch(() => {}); + response_promise.then(res => { + const res_type = this.getRequestType(res); + if (res_type) { + this.defineMeasure(res_type); + } + }); return response_promise; }; - sendRequestsStatistic = is_bot_running => { - REQUESTS.forEach(req_type => { - const measure = performance.getEntriesByName(req_type); - if (measure && measure.length) { - if (DATADOG_CLIENT_LOGS_TOKEN) { - this.log(measure, is_bot_running, req_type); - } - } - }); + sendRequestsStatistic = () => { + // REQUESTS.forEach(req_type => { + // const measure = performance.getEntriesByName(req_type); + // }); performance.clearMeasures(); }; diff --git a/src/components/ToolBox/ToolBox.jsx b/src/components/ToolBox/ToolBox.jsx index 04e744328..2a917d258 100644 --- a/src/components/ToolBox/ToolBox.jsx +++ b/src/components/ToolBox/ToolBox.jsx @@ -231,7 +231,10 @@ const ToolBox = ({ id_container='runButton' tooltip={translate('Run the bot')} position='bottom' - onClick={() => globalObserver.emit('blockly.start')} + onClick={() => { + globalObserver.emit("blockly.start") + performance.mark('bot-start'); + }} classes={classNames('toolbox-button icon-run', { 'toolbox-hide': !is_workspace_rendered, })}