-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1389 from dpc-sdp/feature/SD-387-new-relic-browser
[SD-387] Added newrelic browser agent
- Loading branch information
Showing
17 changed files
with
218 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
packages/nuxt-ripple-analytics/composables/useNewRelicBrowserAgent.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import type { IRplFeatureFlags } from '@dpc-sdp/ripple-tide-api/types' | ||
|
||
export default () => { | ||
const config = useRuntimeConfig() | ||
const browserAgentConfig = config?.public?.newRelic?.browser | ||
|
||
if (!browserAgentConfig.enabled) { | ||
return | ||
} | ||
|
||
const featureFlags: IRplFeatureFlags = inject('featureFlags', { | ||
newRelicBrowserBeacon: 'bam.nr-data.net', | ||
newRelicBrowserJSErrorsEnabled: true, | ||
newRelicBrowserCookiesEnabled: false, | ||
newRelicBrowserDistributedTracingEnabled: false, | ||
newRelicBrowserAjaxDenyList: ['bam.nr-data.net'] | ||
}) | ||
|
||
// Scripts from new relic need to be dynamically imported, otherwise they will throw an error | ||
const initBrowserAgent = async () => { | ||
// Error module has to be manually added when using new relic via npm | ||
const { JSErrors } = await import( | ||
'@newrelic/browser-agent/features/jserrors' | ||
) | ||
|
||
const options = { | ||
info: { | ||
beacon: featureFlags.newRelicBrowserBeacon, | ||
licenseKey: browserAgentConfig.licenseKey, | ||
applicationID: browserAgentConfig.applicationID, | ||
sa: 1 // 'sa' stands for 'standalone' https://github.com/newrelic/newrelic-browser-agent/blob/bbf414c0d6a483141f32e2dd31b1f8a23ad1dda5/src/features/logging/aggregate/index.js#L100 | ||
}, | ||
init: { | ||
distributed_tracing: { | ||
enabled: featureFlags.newRelicBrowserDistributedTracingEnabled | ||
}, | ||
privacy: { | ||
cookies_enabled: featureFlags.newRelicBrowserCookiesEnabled | ||
}, | ||
jserrors: { enabled: featureFlags.newRelicBrowserJSErrorsEnabled }, | ||
ajax: { deny_list: featureFlags.newRelicBrowserAjaxDenyList } | ||
}, | ||
loader_config: { | ||
accountID: browserAgentConfig.accountID, | ||
trustKey: browserAgentConfig.trustKey, | ||
agentID: browserAgentConfig.agentID, | ||
licenseKey: browserAgentConfig.licenseKey, | ||
applicationID: browserAgentConfig.applicationID | ||
}, | ||
features: [JSErrors] | ||
} | ||
|
||
const { BrowserAgent } = await import( | ||
'@newrelic/browser-agent/loaders/browser-agent' | ||
) | ||
|
||
new BrowserAgent(options) | ||
} | ||
|
||
if (process.client) { | ||
initBrowserAgent() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { defineNuxtPlugin } from '#app' | ||
import trackError from '../utils/trackError' | ||
|
||
export default defineNuxtPlugin((nuxtApp) => { | ||
/* @ts-ignore process is extended by webpack */ | ||
if (process.client) { | ||
nuxtApp.vueApp.use({ | ||
install(app: any) { | ||
useNewRelicBrowserAgent() | ||
|
||
const existingErrorHandler = app.config.errorHandler | ||
|
||
// Catch all vue errors | ||
app.config.errorHandler = (error: Error) => { | ||
console.error(error) | ||
trackError(error) | ||
|
||
// Allow multiple error handlers to run | ||
if ( | ||
existingErrorHandler && | ||
typeof existingErrorHandler === 'function' | ||
) { | ||
existingErrorHandler(error) | ||
} | ||
} | ||
} | ||
}) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
declare global { | ||
interface Window { | ||
newrelic?: { | ||
noticeError: (error: any) => void | ||
} | ||
} | ||
} | ||
|
||
const trackError = (error: any) => { | ||
if (window?.newrelic?.noticeError) { | ||
window.newrelic.noticeError(error) | ||
} | ||
} | ||
|
||
export default trackError |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.