feat(observability): integrate Sentry error tracking for API and Web apps

- API: add @sentry/nestjs with instrument.ts, SentryModule, and SentryGlobalFilter
- Web: add @sentry/nextjs with client/server/edge configs, instrumentation hook
- Update next.config.js with withSentryConfig wrapper
- Replace TODO in error.tsx with Sentry.captureException
- Add SENTRY_DSN, SENTRY_AUTH_TOKEN, SENTRY_ORG, SENTRY_PROJECT to .env.example

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
Ho Ngoc Hai
2026-04-08 13:44:57 +07:00
parent 767afb56d5
commit 400a75845c
13 changed files with 1371 additions and 21 deletions

View File

@@ -27,6 +27,8 @@
"@paralleldrive/cuid2": "^3.3.0",
"@prisma/adapter-pg": "^7.7.0",
"@prisma/client": "^7.7.0",
"@sentry/nestjs": "^10.47.0",
"@sentry/profiling-node": "^10.47.0",
"@willsoto/nestjs-prometheus": "^6.1.0",
"bcrypt": "^6.0.0",
"class-transformer": "^0.5.1",

View File

@@ -1,7 +1,8 @@
import { type MiddlewareConsumer, Module, type NestModule } from '@nestjs/common';
import { APP_GUARD } from '@nestjs/core';
import { APP_FILTER, APP_GUARD } from '@nestjs/core';
import { CqrsModule } from '@nestjs/cqrs';
import { ThrottlerModule } from '@nestjs/throttler';
import { SentryGlobalFilter, SentryModule } from '@sentry/nestjs/setup';
import { AdminModule } from '@modules/admin';
import { AnalyticsModule } from '@modules/analytics';
import { AuthModule } from '@modules/auth';
@@ -20,6 +21,7 @@ import { AppController } from './app.controller';
@Module({
imports: [
SentryModule.forRoot(),
CqrsModule.forRoot(),
SharedModule,
AuthModule,
@@ -58,6 +60,10 @@ import { AppController } from './app.controller';
],
controllers: [AppController],
providers: [
{
provide: APP_FILTER,
useClass: SentryGlobalFilter,
},
{
provide: APP_GUARD,
useClass: ThrottlerBehindProxyGuard,

View File

@@ -0,0 +1,11 @@
import * as Sentry from '@sentry/nestjs';
import { nodeProfilingIntegration } from '@sentry/profiling-node';
Sentry.init({
dsn: process.env['SENTRY_DSN'],
environment: process.env['NODE_ENV'] ?? 'development',
integrations: [nodeProfilingIntegration()],
tracesSampleRate: process.env['NODE_ENV'] === 'production' ? 0.2 : 1.0,
profilesSampleRate: process.env['NODE_ENV'] === 'production' ? 0.2 : 1.0,
enabled: !!process.env['SENTRY_DSN'],
});

View File

@@ -1,3 +1,5 @@
import './instrument';
import { ValidationPipe } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';