Intégration Sentry SaaS pour error monitoring + replay sur les 2 apps.
API (apps/api) :
- start/sentry.ts : init au plus tôt dans bin/server.ts (avant Ignitor)
pour capturer les erreurs de bootstrap. No-op si SENTRY_DSN_API absent.
- app/exceptions/handler.ts:report : captureException sur les 5xx avec
tags { url, method, status } et user.id (PII minimisée). 4xx filtrés
par beforeSend dans start/sentry.ts (validation, auth invalide = bruit).
- start/env.ts : SENTRY_DSN_API + APP_VERSION optionnels.
- bin/server.ts : import #start/sentry en 1er.
- @sentry/node + @sentry/profiling-node ajoutés au package.json.
Web (apps/web) :
- src/lib/sentry.ts : init au plus tôt dans main.tsx, BrowserTracing +
Replay (0% session, 100% sur erreur — économie quota free tier).
maskAllText + blockAllMedia pour privacy par défaut.
- src/lib/auth.ts : Sentry.setUser({ id }) au login, setUser(null) au
logout (corrélation cross-stack des erreurs front avec un user).
- src/main.tsx : ErrorBoundary autour de l'app avec FallbackError UX.
- vite.config.ts : @sentry/vite-plugin uploads les sourcemaps + les
SUPPRIME du dist/ final (filesToDeleteAfterUpload) pour ne pas leak
le code source via nginx en prod. Helper resolveAppVersion() pour
injecter le sha git en dev (le shell n'étant pas évaluable dans .env).
- src/lib/env.ts : VITE_SENTRY_DSN_WEB + VITE_APP_VERSION optionnels.
- .env.development : VITE_SENTRY_DSN_WEB (préfixé correctement pour
être exposé par Vite — l'ancienne SENTRY_DSN ne marchait pas).
- @sentry/react + @sentry/vite-plugin ajoutés au package.json.
CI Gitea :
- deploy-api.yml : kubectl set env APP_VERSION=${{ github.sha }}
runtime → release Sentry trackable au commit pour l'API.
- deploy-web.yml : build-args VITE_SENTRY_DSN_WEB, VITE_APP_VERSION,
SENTRY_AUTH_TOKEN, SENTRY_ORG injectés depuis les secrets Gitea.
- Dockerfile.web : ARG correspondants + propagation au stage build.
Privacy / sécurité (cf. ADR-024) :
- captureException tags : ctx.route?.pattern (pas l'URL réelle) →
les codes OAuth (?code=...) et tokens de check-in n'apparaissent
jamais dans les tags Sentry indexés.
- Sentry user context = user.id UUID seulement, pas d'email/nom.
- Sourcemaps en prod : uploadées à Sentry, supprimées du bundle.
- 4xx filtrées en amont (beforeSend) ET en aval (handler.ts:report).
- DSN public (by-design) commit-able, AUTH_TOKEN secret CI uniquement.
Sample rates (free tier 5K events / 50 replays par mois) :
- traces : 10% prod, 100% dev
- profiles : 100% (sampled par traces)
- replay session : 0% (économie quota)
- replay sur erreur : 100% (debug post-mortem)
Pré-requis runtime à configurer hors-repo :
- Secret K3s rubis-app-secrets : SENTRY_DSN_API
- Secrets Gitea Actions : SENTRY_DSN_WEB, SENTRY_AUTH_TOKEN, SENTRY_ORG
ADR-024 logué dans docs/decisions.md.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
107 lines
4.0 KiB
TypeScript
107 lines
4.0 KiB
TypeScript
/*
|
|
|--------------------------------------------------------------------------
|
|
| Environment variables service
|
|
|--------------------------------------------------------------------------
|
|
|
|
|
| The `Env.create` method creates an instance of the Env service. The
|
|
| service validates the environment variables and also cast values
|
|
| to JavaScript data types.
|
|
|
|
|
*/
|
|
|
|
import { Env } from '@adonisjs/core/env'
|
|
|
|
export default await Env.create(new URL('../', import.meta.url), {
|
|
// Node
|
|
NODE_ENV: Env.schema.enum(['development', 'production', 'test'] as const),
|
|
PORT: Env.schema.number(),
|
|
HOST: Env.schema.string({ format: 'host' }),
|
|
LOG_LEVEL: Env.schema.string(),
|
|
|
|
// App
|
|
APP_KEY: Env.schema.secret(),
|
|
APP_URL: Env.schema.string({ format: 'url', tld: false }),
|
|
|
|
// Session
|
|
SESSION_DRIVER: Env.schema.enum(['cookie', 'memory', 'database'] as const),
|
|
|
|
// Database
|
|
DB_CONNECTION: Env.schema.enum.optional(['postgres', 'sqlite'] as const),
|
|
PG_HOST: Env.schema.string.optional({ format: 'host' }),
|
|
PG_PORT: Env.schema.number.optional(),
|
|
PG_USER: Env.schema.string.optional(),
|
|
PG_PASSWORD: Env.schema.string.optional(),
|
|
PG_DB_NAME: Env.schema.string.optional(),
|
|
|
|
// Redis (BullMQ + cache)
|
|
REDIS_HOST: Env.schema.string.optional({ format: 'host' }),
|
|
REDIS_PORT: Env.schema.number.optional(),
|
|
REDIS_PASSWORD: Env.schema.string.optional(),
|
|
|
|
// Storage (MinIO via S3 driver)
|
|
DRIVE_DISK: Env.schema.enum.optional(['s3', 'fs'] as const),
|
|
S3_ENDPOINT: Env.schema.string.optional({ format: 'url', tld: false }),
|
|
S3_REGION: Env.schema.string.optional(),
|
|
S3_BUCKET: Env.schema.string.optional(),
|
|
S3_ACCESS_KEY: Env.schema.string.optional(),
|
|
S3_SECRET_KEY: Env.schema.string.optional(),
|
|
S3_FORCE_PATH_STYLE: Env.schema.boolean.optional(),
|
|
|
|
// Mail
|
|
MAIL_FROM_ADDRESS: Env.schema.string.optional(),
|
|
MAIL_FROM_NAME: Env.schema.string.optional(),
|
|
MAIL_DRIVER: Env.schema.enum.optional(['smtp', 'resend'] as const),
|
|
SMTP_HOST: Env.schema.string.optional({ format: 'host' }),
|
|
SMTP_PORT: Env.schema.number.optional(),
|
|
RESEND_API_KEY: Env.schema.string.optional(),
|
|
|
|
// OCR
|
|
OCR_PROVIDER: Env.schema.enum.optional(['mock', 'mistral'] as const),
|
|
MISTRAL_API_KEY: Env.schema.string.optional(),
|
|
|
|
// Stripe — secret key + webhook signing secret. Optional en dev sans
|
|
// billing actif. La commande `stripe:setup` et le webhook handler les
|
|
// exigent au runtime.
|
|
STRIPE_SECRET_KEY: Env.schema.string.optional(),
|
|
STRIPE_WEBHOOK_SECRET: Env.schema.string.optional(),
|
|
|
|
// Web (URL du SPA pour redirects post-checkin)
|
|
WEB_URL: Env.schema.string.optional({ format: 'url', tld: false }),
|
|
|
|
// Landing public (lien dans le footer des emails — branding)
|
|
LANDING_URL: Env.schema.string.optional({ format: 'url', tld: false }),
|
|
|
|
// Auth
|
|
ACCESS_TOKEN_TTL_MINUTES: Env.schema.number.optional(),
|
|
REFRESH_TOKEN_TTL_DAYS: Env.schema.number.optional(),
|
|
COOKIE_DOMAIN: Env.schema.string.optional(),
|
|
COOKIE_SECURE: Env.schema.boolean.optional(),
|
|
|
|
// Google SSO (Ally)
|
|
GOOGLE_CLIENT_ID: Env.schema.string.optional(),
|
|
GOOGLE_CLIENT_SECRET: Env.schema.string.optional(),
|
|
GOOGLE_CALLBACK_URL: Env.schema.string.optional({ format: 'url', tld: false }),
|
|
|
|
// Microsoft SSO (Ally)
|
|
MICROSOFT_CLIENT_ID: Env.schema.string.optional(),
|
|
MICROSOFT_CLIENT_SECRET: Env.schema.string.optional(),
|
|
MICROSOFT_TENANT: Env.schema.string.optional(),
|
|
MICROSOFT_CALLBACK_URL: Env.schema.string.optional({ format: 'url', tld: false }),
|
|
|
|
/*
|
|
|----------------------------------------------------------
|
|
| Variables for configuring the limiter package
|
|
|----------------------------------------------------------
|
|
*/
|
|
LIMITER_STORE: Env.schema.enum(['redis', 'memory'] as const),
|
|
|
|
/*
|
|
|----------------------------------------------------------
|
|
| Sentry — error monitoring (cf. apps/api/start/sentry.ts)
|
|
|----------------------------------------------------------
|
|
| Optionnels en dev local. Si non définis, Sentry est no-op.
|
|
*/
|
|
SENTRY_DSN_API: Env.schema.string.optional(),
|
|
APP_VERSION: Env.schema.string.optional(),
|
|
})
|