From ef37e83aadacda29d54ae5a82610b4a877a11ddb Mon Sep 17 00:00:00 2001 From: Shivam Mishra Date: Thu, 13 Mar 2025 11:57:48 +0530 Subject: [PATCH] refactor: use window.newrelic directly --- .../store/modules/conversations/index.js | 18 ++++++++++++------ app/javascript/entrypoints/dashboard.js | 7 ------- .../shared/helpers/BaseActionCableConnector.js | 9 ++++++--- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/app/javascript/dashboard/store/modules/conversations/index.js b/app/javascript/dashboard/store/modules/conversations/index.js index 760edf83b..924717e3e 100644 --- a/app/javascript/dashboard/store/modules/conversations/index.js +++ b/app/javascript/dashboard/store/modules/conversations/index.js @@ -229,9 +229,12 @@ export const mutations = { Sentry.captureMessage('Conversation update mismatch'); }); - window.logrelic( - `conversation update mismatch for ${conversation.id} with incoming ${JSON.stringify(conversation, null, 2)} and stored ${JSON.stringify(selectedConversation, null, 2)}` - ); + if (window.newrelic) { + window.newrelic.log( + `conversation update mismatch for ${conversation.id} with incoming ${JSON.stringify(conversation, null, 2)} and stored ${JSON.stringify(selectedConversation, null, 2)}`, + { level: 'DEBUG' } + ); + } return; } @@ -250,9 +253,12 @@ export const mutations = { Sentry.captureMessage('Conversation update overlap'); }); - window.logrelic( - `conversation update overlap for ${conversation.id} with incoming ${JSON.stringify(conversation, null, 2)} and stored ${JSON.stringify(selectedConversation, null, 2)}` - ); + if (window.newrelic) { + window.newrelic.log( + `conversation update overlap for ${conversation.id} with incoming ${JSON.stringify(conversation, null, 2)} and stored ${JSON.stringify(selectedConversation, null, 2)}`, + { level: 'DEBUG' } + ); + } } const { messages, ...updates } = conversation; diff --git a/app/javascript/entrypoints/dashboard.js b/app/javascript/entrypoints/dashboard.js index f02cc3adf..a2184d074 100644 --- a/app/javascript/entrypoints/dashboard.js +++ b/app/javascript/entrypoints/dashboard.js @@ -21,7 +21,6 @@ import router, { initalizeRouter } from 'dashboard/routes'; import store from 'dashboard/store'; import constants from 'dashboard/constants/globals'; import * as Sentry from '@sentry/vue'; - import { initializeAnalyticsEvents, initializeChatwootEvents, @@ -48,12 +47,6 @@ app.use(i18n); app.use(store); app.use(router); -window.logrelic = (message, options = {}) => { - if (window.newrelic) { - window.newrelic.log(message, { level: 'debug' }, options); - } -}; - // [VITE] Disabled this, need to renable later if (window.errorLoggingConfig) { Sentry.init({ diff --git a/app/javascript/shared/helpers/BaseActionCableConnector.js b/app/javascript/shared/helpers/BaseActionCableConnector.js index f39835095..cbd4484a6 100644 --- a/app/javascript/shared/helpers/BaseActionCableConnector.js +++ b/app/javascript/shared/helpers/BaseActionCableConnector.js @@ -82,9 +82,12 @@ class BaseActionCableConnector { onReceived = ({ event, data } = {}) => { if (this.isAValidEvent(data)) { if (this.events[event] && typeof this.events[event] === 'function') { - window.logrelic( - `processing actioncable ${event} with ${JSON.stringify(data, null, 2)} at ${Number(Date.now())}` - ); + if (window.newrelic) { + window.newrelic.log( + `processing actioncable ${event} with ${JSON.stringify(data, null, 2)} at ${Number(Date.now())}`, + { level: 'DEBUG' } + ); + } this.events[event](data); } }