Scheduling infrastructure for absolutely everyone.
chore: add sentry performance tracking api-v2 (#17519)
Morgan79f0754bf726
diff --git a/apps/api/v2/package.json b/apps/api/v2/package.jsonindex 6dffb53412e..77cbe4910d2 100644--- a/apps/api/v2/package.json+++ b/apps/api/v2/package.json@@ -45,7 +45,9 @@"@nestjs/platform-express": "^10.0.0","@nestjs/swagger": "^7.3.0","@nestjs/throttler": "6.2.1",+ "@sentry/nestjs": "^8.37.1","@sentry/node": "^8.8.0",+ "@sentry/profiling-node": "^8.37.1","body-parser": "^1.20.2","bull": "^4.12.4","class-transformer": "^0.5.1",diff --git a/apps/api/v2/src/app.module.ts b/apps/api/v2/src/app.module.tsindex e4c16937531..b9bd76cfd7a 100644--- a/apps/api/v2/src/app.module.ts+++ b/apps/api/v2/src/app.module.ts@@ -17,13 +17,15 @@ import { ThrottlerStorageRedisService } from "@nest-lab/throttler-storage-redis"import { BullModule } from "@nestjs/bull";import { MiddlewareConsumer, Module, NestModule, RequestMethod } from "@nestjs/common";import { ConfigModule } from "@nestjs/config";-import { APP_GUARD, APP_INTERCEPTOR } from "@nestjs/core";+import { APP_GUARD, APP_INTERCEPTOR, APP_FILTER } from "@nestjs/core";import { seconds, ThrottlerModule } from "@nestjs/throttler";+import { SentryModule, SentryGlobalFilter } from "@sentry/nestjs/setup";import { AppController } from "./app.controller";@Module({imports: [+ SentryModule.forRoot(),ConfigModule.forRoot({ignoreEnvFile: true,isGlobal: true,@@ -59,6 +61,10 @@ import { AppController } from "./app.controller";],controllers: [AppController],providers: [+ {+ provide: APP_FILTER,+ useClass: SentryGlobalFilter,+ },{provide: ThrottlerStorageRedisService,useFactory: (redisService: RedisService) => {diff --git a/apps/api/v2/src/app.ts b/apps/api/v2/src/app.tsindex 3ce349268c1..b452d0ddca2 100644--- a/apps/api/v2/src/app.ts+++ b/apps/api/v2/src/app.ts@@ -7,7 +7,6 @@ import type { ValidationError } from "@nestjs/common";import { BadRequestException, ValidationPipe, VersioningType } from "@nestjs/common";import { BaseExceptionFilter, HttpAdapterHost } from "@nestjs/core";import type { NestExpressApplication } from "@nestjs/platform-express";-import * as Sentry from "@sentry/node";import * as cookieParser from "cookie-parser";import { Request } from "express";import helmet from "helmet";@@ -71,9 +70,6 @@ export const bootstrap = (app: NestExpressApplication): NestExpressApplication =// Exception filters, new filters go at the bottom, keep the orderconst { httpAdapter } = app.get(HttpAdapterHost);- if (process.env.SENTRY_DSN) {- Sentry.setupNestErrorHandler(app, new BaseExceptionFilter(httpAdapter));- }app.useGlobalFilters(new PrismaExceptionFilter());app.useGlobalFilters(new ZodExceptionFilter());app.useGlobalFilters(new HttpExceptionFilter());diff --git a/apps/api/v2/src/env.ts b/apps/api/v2/src/env.tsindex b81b5a81f82..833a8161441 100644--- a/apps/api/v2/src/env.ts+++ b/apps/api/v2/src/env.ts@@ -10,6 +10,8 @@ export type Environment = {DATABASE_URL: string;JWT_SECRET: string;SENTRY_DSN: string;+ SENTRY_TRACES_SAMPLE_RATE?: number;+ SENTRY_PROFILES_SAMPLE_RATE?: number;LOG_LEVEL: keyof typeof logLevels;REDIS_URL: string;STRIPE_API_KEY: string;diff --git a/apps/api/v2/src/instrument.ts b/apps/api/v2/src/instrument.tsindex 77c172854e2..a579907a2b7 100644--- a/apps/api/v2/src/instrument.ts+++ b/apps/api/v2/src/instrument.ts@@ -1,12 +1,15 @@import { getEnv } from "@/env";-import * as Sentry from "@sentry/node";+import * as Sentry from "@sentry/nestjs";+import { nodeProfilingIntegration } from "@sentry/profiling-node";if (process.env.SENTRY_DSN) {// Ensure to call this before requiring any other modules!Sentry.init({dsn: getEnv("SENTRY_DSN"),- // Add Performance Monitoring by setting tracesSampleRate- // We recommend adjusting this value in production- // todo: Evaluate? tracesSampleRate: 1.0+ integrations: [nodeProfilingIntegration()],+ // Performance Monitoring+ tracesSampleRate: getEnv("SENTRY_TRACES_SAMPLE_RATE") ?? 1.0, // Capture 100% of the transactions+ // Set sampling rate for profiling - this is relative to tracesSampleRate+ profilesSampleRate: getEnv("SENTRY_PROFILES_SAMPLE_RATE") ?? 1.0,});}