123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- import {browserHistory, createRoutes, match} from 'react-router';
- import {ExtraErrorData} from '@sentry/integrations';
- import * as Sentry from '@sentry/react';
- import SentryRRWeb from '@sentry/rrweb';
- import {Integrations} from '@sentry/tracing';
- import {_browserPerformanceTimeOriginMode} from '@sentry/utils';
- import {DISABLE_RR_WEB, SPA_DSN} from 'app/constants';
- import {Config} from 'app/types';
- import {init as initApiSentryClient} from 'app/utils/apiSentryClient';
- function getSentryIntegrations(hasReplays: boolean = false, routes?: Function) {
- const integrations = [
- new ExtraErrorData({
-
- depth: 6,
- }),
- new Integrations.BrowserTracing({
- ...(typeof routes === 'function'
- ? {
- routingInstrumentation: Sentry.reactRouterV3Instrumentation(
- browserHistory as any,
- createRoutes(routes()),
- match
- ),
- }
- : {}),
- idleTimeout: 5000,
- _metricOptions: {
- _reportAllChanges: true,
- },
- }),
- ];
- if (hasReplays) {
-
- console.log('[sentry] Instrumenting session with rrweb');
-
-
-
- integrations.push(
- new SentryRRWeb({
- checkoutEveryNms: 60 * 1000,
- }) as any
- );
- }
- return integrations;
- }
- export function initializeSdk(config: Config, {routes}: {routes?: Function} = {}) {
- if (config.dsn_requests) {
- initApiSentryClient(config.dsn_requests);
- }
- const {apmSampling, sentryConfig, userIdentity} = config;
- const tracesSampleRate = apmSampling ?? 0;
- const hasReplays = userIdentity?.isStaff && !DISABLE_RR_WEB;
- Sentry.init({
- ...sentryConfig,
-
- dsn: SPA_DSN || sentryConfig?.dsn,
- whitelistUrls: SPA_DSN
- ? ['localhost', 'dev.getsentry.net', 'sentry.dev', 'webpack-internal://']
- : sentryConfig?.whitelistUrls,
- integrations: getSentryIntegrations(hasReplays, routes),
- tracesSampleRate,
-
- ignoreErrors: ['AbortError: Fetch is aborted'],
- });
-
- Sentry.addGlobalEventProcessor((event: Sentry.Event, _hint?: Sentry.EventHint) => {
- event.tags = event.tags || {};
- event.tags['timeOrigin.mode'] = _browserPerformanceTimeOriginMode;
- return event;
- });
- if (userIdentity) {
- Sentry.setUser(userIdentity);
- }
- if (window.__SENTRY__VERSION) {
- Sentry.setTag('sentry_version', window.__SENTRY__VERSION);
- }
- Sentry.setTag('rrweb.active', hasReplays ? 'yes' : 'no');
- }
|