instrument.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import type { ConsoleLevel } from '@sentry/core';
  2. import * as Sentry from '@sentry/nestjs';
  3. import { nodeProfilingIntegration } from '@sentry/profiling-node';
  4. const SENTRY_DSN = process.env.SENTRY_DSN;
  5. const SENTRY_TRACES_SAMPLE_RATE = process.env.SENTRY_TRACES_SAMPLE_RATE
  6. ? Number(process.env.SENTRY_TRACES_SAMPLE_RATE)
  7. : undefined;
  8. const SENTRY_PROFILES_SAMPLE_RATE = process.env.SENTRY_PROFILES_SAMPLE_RATE
  9. ? Number(process.env.SENTRY_PROFILES_SAMPLE_RATE)
  10. : undefined;
  11. const SENTRY_ENABLE_LOGS = process.env.SENTRY_ENABLE_LOGS === 'true';
  12. const SENTRY_CAPTURE_LOG_LEVELS = process.env.SENTRY_CAPTURE_LOG_LEVELS
  13. ? process.env.SENTRY_CAPTURE_LOG_LEVELS.split(',').map(l => l.trim())
  14. : ['log', 'warn', 'error'];
  15. if (!SENTRY_DSN) {
  16. // eslint-disable-next-line
  17. console.error('SENTRY_DSN is not set');
  18. } else {
  19. Sentry.init({
  20. dsn: SENTRY_DSN,
  21. integrations: [
  22. nodeProfilingIntegration(),
  23. ...(SENTRY_ENABLE_LOGS
  24. ? [Sentry.consoleLoggingIntegration({ levels: SENTRY_CAPTURE_LOG_LEVELS as ConsoleLevel[] })]
  25. : []),
  26. ],
  27. /**
  28. * @description
  29. * The sample rate for tracing. Value should be between 0 and 1.
  30. * By default, tracing is disabled.
  31. * @default undefined
  32. */
  33. tracesSampleRate: SENTRY_TRACES_SAMPLE_RATE,
  34. /**
  35. * @description
  36. * The sample rate for profiling. Value should be between 0 and 1.
  37. * By default, profiling is disabled.
  38. * @default undefined
  39. */
  40. profilesSampleRate: SENTRY_PROFILES_SAMPLE_RATE,
  41. /**
  42. * @description
  43. * Enable logs to be sent to Sentry.
  44. * @default false
  45. */
  46. enableLogs: SENTRY_ENABLE_LOGS,
  47. });
  48. }