@igo2/core
Version:
1 lines • 6.38 kB
Source Map (JSON)
{"version":3,"file":"igo2-core-monitoring.mjs","sources":["../../../packages/core/monitoring/src/shared/monitoring.ts","../../../packages/core/monitoring/src/sentry/sentry.ts","../../../packages/core/monitoring/src/sentry/sentry.provider.ts","../../../packages/core/monitoring/src/sentry/sentry.utils.ts","../../../packages/core/monitoring/src/__mocks__/monitoring-mock.ts","../../../packages/core/monitoring/src/igo2-core-monitoring.ts"],"sourcesContent":["import { InjectionToken } from '@angular/core';\n\nimport { MonitoringOptions } from './monitoring.interface';\n\nexport const MONITORING_OPTIONS = new InjectionToken<MonitoringOptions | null>(\n 'monitoring.options'\n);\n","import {\n BrowserOptions,\n SentryErrorHandler,\n createErrorHandler,\n getClient,\n init\n} from '@sentry/angular';\n\nimport { SentryMonitoringOptions } from './sentry.interface';\n\nexport const createSentryErrorHandler = (\n options: SentryMonitoringOptions\n): SentryErrorHandler => {\n return createErrorHandler({\n logErrors: options.logErrors,\n ...(options.errorHandlerOptions ?? {})\n });\n};\n\nexport const initSentry = (\n options: SentryMonitoringOptions,\n force?: boolean\n): void => {\n const client = getClient();\n if (!force && client) {\n return;\n }\n\n init(options as unknown as BrowserOptions);\n};\n","import {\n EnvironmentProviders,\n ErrorHandler,\n Provider,\n inject,\n provideAppInitializer\n} from '@angular/core';\nimport { Router } from '@angular/router';\n\nimport { TraceService, browserTracingIntegration } from '@sentry/angular';\n\nimport { MONITORING_OPTIONS } from '../shared';\nimport { createSentryErrorHandler, initSentry } from './sentry';\nimport { SentryMonitoringOptions } from './sentry.interface';\n\nexport const provideSentryMonitoring = (\n options: SentryMonitoringOptions,\n integrations?: SentryIntegrationFactory<SentryIntegrationKind>[]\n): (Provider | EnvironmentProviders)[] => {\n const isEnabled = options.enabled !== undefined ? options.enabled : true;\n if (!isEnabled) {\n return [];\n }\n\n const providers: (Provider | EnvironmentProviders)[] = [\n { provide: MONITORING_OPTIONS, useValue: options },\n {\n provide: ErrorHandler,\n useFactory: () => createSentryErrorHandler(options)\n }\n ];\n\n if (integrations) {\n for (const integration of integrations) {\n const value = integration(options);\n providers.push(...value.providers);\n }\n }\n\n initSentry(options);\n\n return providers;\n};\n\nexport interface SentryIntegration<KindT extends SentryIntegrationKind> {\n kind: KindT;\n providers: (Provider | EnvironmentProviders)[];\n}\n\ntype SentryIntegrationFactory<KindT extends SentryIntegrationKind> = (\n sentryOptions: SentryMonitoringOptions\n) => SentryIntegration<KindT>;\n\nexport enum SentryIntegrationKind {\n Tracing = 0,\n Replay = 1\n}\n\nexport function withTracingIntegration(\n options: Parameters<typeof browserTracingIntegration>[0]\n): SentryIntegrationFactory<SentryIntegrationKind.Tracing> {\n return (sentryOptions: SentryMonitoringOptions) => {\n sentryOptions.integrations = [\n ...(sentryOptions.integrations ?? []),\n browserTracingIntegration(options)\n ];\n\n return {\n kind: SentryIntegrationKind.Tracing,\n providers: [\n {\n provide: TraceService,\n deps: [Router]\n },\n // Force instantiate TraceService to avoid require it in any constructor.\n provideAppInitializer(() => {\n inject(TraceService);\n return;\n })\n ]\n };\n };\n}\n","import { BaseUser } from '@igo2/core/user';\n\nimport { setUser } from '@sentry/angular';\n\nexport const identifySentryUser = (user: BaseUser | null): void => {\n setUser(\n user\n ? {\n id: user.id,\n username: `${user.firstName} ${user.lastName}`,\n email: user.email\n }\n : null\n );\n};\n","import { SentryMonitoringOptions } from '../sentry';\nimport { AnyMonitoringOptions } from '../shared';\n\nexport const MOCK_SENTRY_OPTIONS: SentryMonitoringOptions = {\n provider: 'sentry',\n dsn: 'https://examplePublicKey@o0.ingest.sentry.io/0',\n identifyUser: true\n};\n\nexport const MOCK_MONITORING_OPTIONS: AnyMonitoringOptions =\n MOCK_SENTRY_OPTIONS;\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public_api';\n"],"names":[],"mappings":";;;;MAIa,kBAAkB,GAAG,IAAI,cAAc,CAClD,oBAAoB;;ACKf,MAAM,wBAAwB,GAAG,CACtC,OAAgC,KACV;AACtB,IAA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