47 lines
1.5 KiB
TypeScript
47 lines
1.5 KiB
TypeScript
|
|
import { FetchTransport, getWebInstrumentations, initializeFaro,InternalLoggerLevel } from '@grafana/faro-web-sdk'
|
||
|
|
import { TracingInstrumentation } from '@grafana/faro-web-tracing'
|
||
|
|
import { FetchInstrumentation } from '@opentelemetry/instrumentation-fetch'
|
||
|
|
|
||
|
|
import { envConfig } from '~/utils/environment'
|
||
|
|
const config = envConfig(window.location.hostname)
|
||
|
|
|
||
|
|
export default defineNuxtPlugin((nuxtApp) => {
|
||
|
|
if (config.grafanaUrl) {
|
||
|
|
const faro = initializeFaro({
|
||
|
|
app: {
|
||
|
|
name: 'Shiny Frontend',
|
||
|
|
version: '1.0.0',
|
||
|
|
environment: config.name,
|
||
|
|
},
|
||
|
|
sessionTracking: {
|
||
|
|
samplingRate: config.tracesSampleRate,
|
||
|
|
},
|
||
|
|
instrumentations: [
|
||
|
|
// Mandatory, omits default instrumentations otherwise.
|
||
|
|
...getWebInstrumentations(),
|
||
|
|
|
||
|
|
// Tracing package to get end-to-end visibility for HTTP requests.
|
||
|
|
new TracingInstrumentation({
|
||
|
|
instrumentations: [
|
||
|
|
new FetchInstrumentation({
|
||
|
|
ignoreUrls: [
|
||
|
|
config.grafanaUrl,
|
||
|
|
config.apiUrl,
|
||
|
|
new RegExp('.*/sw.js$'),
|
||
|
|
new RegExp('.*_payload.json.*'),
|
||
|
|
new RegExp(`https://${config.auth.domain}/*`),
|
||
|
|
],
|
||
|
|
}),
|
||
|
|
],
|
||
|
|
}),
|
||
|
|
],
|
||
|
|
internalLoggerLevel: InternalLoggerLevel.VERBOSE,
|
||
|
|
transports: [
|
||
|
|
new FetchTransport({ url: config.grafanaUrl }),
|
||
|
|
],
|
||
|
|
})
|
||
|
|
console.log(`initialized faro for ${config.grafanaUrl}, sample-rate ${config.tracesSampleRate * 100}%`)
|
||
|
|
nuxtApp.provide('faro', faro)
|
||
|
|
}
|
||
|
|
})
|