File size: 969 Bytes
c7052c4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
import { Environment } from '../utils/env';
import { createEventRateLimiter } from './createEventRateLimiter';
import * as Sentry from '@sentry/node-core/light';

const sentryEventRateLimiter = createEventRateLimiter({
  globalMaxPerWindow: 50,
  maxPerWindow: 10,
  windowMs: 60_000,
});

export const initializeSentry = () => {
  const env = Environment({});

  if (!env.SENTRY_DSN) {
    return;
  }

  Sentry.init({
    attachStacktrace: true,
    beforeSend: sentryEventRateLimiter,
    dsn: env.SENTRY_DSN,
    environment: env.NODE_ENV,
    initialScope: {
      tags: {
        service: env.SERVICE_NAME,
      },
    },
    integrations: (integrations) => {
      return [
        ...integrations,
        Sentry.extraErrorDataIntegration({
          captureErrorCause: true,
          depth: 5,
        }),
      ];
    },
    maxBreadcrumbs: 20,
    maxValueLength: 50_000,
    normalizeDepth: 8,
    sendDefaultPii: false,
    tracesSampleRate: 0,
  });
};