61 lines
1.6 KiB
TypeScript
61 lines
1.6 KiB
TypeScript
import type {Faro} from '@grafana/faro-react';
|
|
import {getWebInstrumentations, initializeFaro, ReactIntegration} from '@grafana/faro-react';
|
|
import {TracingInstrumentation} from '@grafana/faro-web-tracing';
|
|
|
|
type FaroOptions = {
|
|
url: string;
|
|
apiKey: string;
|
|
appName: string;
|
|
appEnv: string;
|
|
appVersion: string;
|
|
};
|
|
|
|
const options: FaroOptions = {
|
|
url: import.meta.env.VITE_FARO_URL ?? 'https://faro.gitdata.me/collect',
|
|
apiKey: import.meta.env.VITE_FARO_API_KEY ?? '',
|
|
appName: import.meta.env.VITE_FARO_APP_NAME ?? 'GitDataAIWeb',
|
|
appEnv: import.meta.env.VITE_FARO_APP_ENV ?? 'production',
|
|
appVersion: import.meta.env.VITE_FARO_APP_VERSION ?? '0.0.1',
|
|
};
|
|
|
|
let faro: Faro | null = null;
|
|
|
|
export function initRum() {
|
|
if (faro !== null || typeof window === 'undefined') return;
|
|
if (import.meta.env.VITE_FARO_ENABLED === 'false') return;
|
|
|
|
faro = initializeFaro({
|
|
url: options.url,
|
|
apiKey: options.apiKey,
|
|
instrumentations: [
|
|
...getWebInstrumentations({
|
|
captureConsole: true,
|
|
}),
|
|
new TracingInstrumentation(),
|
|
new ReactIntegration(),
|
|
],
|
|
app: {
|
|
name: options.appName,
|
|
version: options.appVersion,
|
|
environment: options.appEnv,
|
|
},
|
|
trackResources: true,
|
|
batching: {
|
|
itemLimit: 100,
|
|
},
|
|
});
|
|
}
|
|
|
|
export function setRumUser(user: { id: string; name: string } | null) {
|
|
if (!faro) return;
|
|
|
|
if (!user) {
|
|
faro.api.resetUser();
|
|
return;
|
|
}
|
|
|
|
faro.api.setUser({
|
|
id: user.id,
|
|
attributes: {name: user.name},
|
|
});
|
|
} |