UNPKG

@hug/ngx-sentry

Version:

Angular wrapper for the official Sentry JavaScript SDK

80 lines (74 loc) 3.42 kB
import * as i0 from '@angular/core'; import { ErrorHandler, APP_INITIALIZER, NgModule, makeEnvironmentProviders } from '@angular/core'; import { Router } from '@angular/router'; import { createErrorHandler, TraceService, getCurrentScope, browserTracingIntegration, replayIntegration, init } from '@sentry/angular'; /* eslint-disable @typescript-eslint/naming-convention */ const NGX_SENTRY_PROVIDERS = (options) => [{ // Automatically send Javascript errors captured by the Angular's error handler provide: ErrorHandler, useValue: createErrorHandler({ showDialog: false, ...options }) }, { // Register SentryTrace as a provider in Angular's DI system provide: TraceService, deps: [Router] }, { // Force instantiating Tracing provide: APP_INITIALIZER, useFactory: () => () => { }, deps: [TraceService], multi: true }]; const setSentryUser = (user) => { getCurrentScope().setUser(user); }; const initSentry = (options) => { const defaultOptions = { autoSessionTracking: true, integrations: [ // Registers and configures the Tracing integration, which automatically instruments your // application to monitor its performance, including custom Angular routing instrumentation browserTracingIntegration(), // Registers the Replay integration, which automatically captures Session Replays replayIntegration() ], // Set tracesSampleRate to 1.0 to capture 100% of transactions for tracing. // We recommend adjusting this value in production tracesSampleRate: 0.2, // Set `tracePropagationTargets` to control for which URLs trace propagation should be enabled tracePropagationTargets: options.tracePropagationTargets ?? ['localhost', /^\//], // This sets the sample rate to be 10%. You may want this to be 100% while // in development and sample at a lower rate in production replaysSessionSampleRate: 0.1, // If the entire session is not sampled, use the below sample rate to sample // sessions when an error occurs. replaysOnErrorSampleRate: 1.0 }; // Initialize Sentry init({ ...defaultOptions, ...options }); }; class NgxSentryModule { static forRoot(options) { return { ngModule: NgxSentryModule, providers: NGX_SENTRY_PROVIDERS(options) }; } static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.5", ngImport: i0, type: NgxSentryModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule }); } static { this.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.2.5", ngImport: i0, type: NgxSentryModule }); } static { this.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.2.5", ngImport: i0, type: NgxSentryModule }); } } i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.5", ngImport: i0, type: NgxSentryModule, decorators: [{ type: NgModule }] }); const provideSentry = (options) => makeEnvironmentProviders(NGX_SENTRY_PROVIDERS(options)); /** * Generated bundle index. Do not edit. */ export { NgxSentryModule, initSentry, provideSentry, setSentryUser }; //# sourceMappingURL=hug-ngx-sentry.mjs.map