@igo2/core
Version:
93 lines (85 loc) • 2.92 kB
JavaScript
import { InjectionToken, ErrorHandler, provideAppInitializer, inject } from '@angular/core';
import { Router } from '@angular/router';
import { createErrorHandler, getClient, init, browserTracingIntegration, TraceService, setUser } from '@sentry/angular';
const MONITORING_OPTIONS = new InjectionToken('monitoring.options');
const createSentryErrorHandler = (options) => {
return createErrorHandler({
logErrors: options.logErrors,
...(options.errorHandlerOptions ?? {})
});
};
const initSentry = (options, force) => {
const client = getClient();
if (!force && client) {
return;
}
init(options);
};
const provideSentryMonitoring = (options, integrations) => {
const isEnabled = options.enabled !== undefined ? options.enabled : true;
if (!isEnabled) {
return [];
}
const providers = [
{ provide: MONITORING_OPTIONS, useValue: options },
{
provide: ErrorHandler,
useFactory: () => createSentryErrorHandler(options)
}
];
if (integrations) {
for (const integration of integrations) {
const value = integration(options);
providers.push(...value.providers);
}
}
initSentry(options);
return providers;
};
var SentryIntegrationKind;
(function (SentryIntegrationKind) {
SentryIntegrationKind[SentryIntegrationKind["Tracing"] = 0] = "Tracing";
SentryIntegrationKind[SentryIntegrationKind["Replay"] = 1] = "Replay";
})(SentryIntegrationKind || (SentryIntegrationKind = {}));
function withTracingIntegration(options) {
return (sentryOptions) => {
sentryOptions.integrations = [
...(sentryOptions.integrations ?? []),
browserTracingIntegration(options)
];
return {
kind: SentryIntegrationKind.Tracing,
providers: [
{
provide: TraceService,
deps: [Router]
},
// Force instantiate TraceService to avoid require it in any constructor.
provideAppInitializer(() => {
inject(TraceService);
return;
})
]
};
};
}
const identifySentryUser = (user) => {
setUser(user
? {
id: user.id,
username: `${user.firstName} ${user.lastName}`,
email: user.email
}
: null);
};
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, SentryIntegrationKind, identifySentryUser, provideSentryMonitoring, withTracingIntegration };
//# sourceMappingURL=igo2-core-monitoring.mjs.map