@igo2/core
Version:
95 lines (87 loc) • 2.92 kB
JavaScript
import { ErrorHandler, APP_INITIALIZER, InjectionToken } from '@angular/core';
import { Router } from '@angular/router';
import { setUser, createErrorHandler, getClient, browserTracingIntegration, replayIntegration, init, TraceService } from '@sentry/angular';
const isTracingEnabled = (options) => !!options.tracesSampleRate || !!options.tracesSampler;
const isReplayEnabled = (options) => !!options.replaysSessionSampleRate || !!options.replaysOnErrorSampleRate;
const identifySentryUser = (user) => {
setUser(user
? {
id: user.id,
username: `${user.firstName} ${user.lastName}`,
email: user.email
}
: null);
};
const createSentryErrorHandler = (options) => {
return createErrorHandler({
logErrors: options.logErrors,
...(options.errorHandlerOptions ?? {})
});
};
const initSentry = (options, force) => {
const client = getClient();
if (!force && client) {
return;
}
const baseConfig = {
...options,
integrations: [
isTracingEnabled(options) && browserTracingIntegration(),
isReplayEnabled(options) && replayIntegration()
].filter(Boolean)
};
init(baseConfig);
};
const provideSentryMonitoring = (options) => {
const isEnabled = options.enabled !== undefined ? options.enabled : true;
if (!isEnabled) {
return [];
}
initSentry(options);
const tracingEnabled = isTracingEnabled(options);
return [
{
provide: ErrorHandler,
useFactory: () => createSentryErrorHandler(options)
},
tracingEnabled && {
provide: TraceService,
deps: [Router]
},
// Force instantiate TraceService to avoid require it in any constructor.
tracingEnabled && {
provide: APP_INITIALIZER,
useFactory: () => () => void 1,
deps: [TraceService],
multi: true
}
].filter(Boolean);
};
const MONITORING_OPTIONS = new InjectionToken('monitoring.options');
function provideMonitoring(options) {
if (!options) {
return [];
}
const providers = [
{ provide: MONITORING_OPTIONS, useValue: options }
];
switch (options.provider) {
case 'sentry':
providers.push(...provideSentryMonitoring(options));
break;
default:
break;
}
return providers;
}
const MOCK_SENTRY_OPTIONS = {
provider: 'sentry',
dsn: 'https://examplePublicKey@o0.ingest.sentry.io/0',
identifyUser: true
};
const MOCK_MONITORING_OPTIONS = MOCK_SENTRY_OPTIONS;
/**
* Generated bundle index. Do not edit.
*/
export { MOCK_MONITORING_OPTIONS, MOCK_SENTRY_OPTIONS, MONITORING_OPTIONS, identifySentryUser, isReplayEnabled, isTracingEnabled, provideMonitoring, provideSentryMonitoring };
//# sourceMappingURL=igo2-core-monitoring.mjs.map