/* |-------------------------------------------------------------------------- | Sentry — error monitoring & performance |-------------------------------------------------------------------------- | | Init au plus tôt dans le boot (avant Ignitor) pour capturer aussi les | erreurs de bootstrap. Lit `process.env` directement car le service Env | d'Adonis n'est pas encore chargé à ce stade. | | Si SENTRY_DSN_API n'est pas défini (dev local typique), Sentry est | simplement no-op — aucun appel réseau. | | Cf. ADR-024 — choix Sentry SaaS, free tier, 2 projects | (rubis-api / rubis-web). */ import * as Sentry from '@sentry/node' import { nodeProfilingIntegration } from '@sentry/profiling-node' const dsn = process.env.SENTRY_DSN_API const environment = process.env.NODE_ENV ?? 'development' const release = process.env.APP_VERSION ?? 'dev' if (dsn) { Sentry.init({ dsn, environment, release, // 10% en prod, 100% en dev pour debug tracesSampleRate: environment === 'production' ? 0.1 : 1.0, profilesSampleRate: 1.0, integrations: [nodeProfilingIntegration()], // Filtre les erreurs 4xx attendues, garde les 5xx beforeSend(event, hint) { const error = hint.originalException as { status?: number } | undefined if (error?.status && error.status >= 400 && error.status < 500) { return null } return event }, }) } export { Sentry }