From d51342f7b0c1092279a7ccea346a559ed6daa131 Mon Sep 17 00:00:00 2001 From: Philipinho <16838612+Philipinho@users.noreply.github.com> Date: Wed, 26 Feb 2025 15:16:24 +0000 Subject: [PATCH] feat: sentry --- apps/server/package.json | 2 ++ apps/server/src/app.module.ts | 2 ++ .../collaboration/server/collab-app.module.ts | 2 ++ .../src/collaboration/server/collab-main.ts | 1 + apps/server/src/common/sentry/instrument.ts | 16 ++++++++++++++++ apps/server/src/main.ts | 1 + 6 files changed, 24 insertions(+) create mode 100644 apps/server/src/common/sentry/instrument.ts diff --git a/apps/server/package.json b/apps/server/package.json index 465e48f1..f5da02b9 100644 --- a/apps/server/package.json +++ b/apps/server/package.json @@ -49,6 +49,8 @@ "@nestjs/websockets": "^11.0.10", "@react-email/components": "0.0.28", "@react-email/render": "1.0.2", + "@sentry/nestjs": "^9.2.0", + "@sentry/profiling-node": "^9.2.0", "@socket.io/redis-adapter": "^8.3.0", "bcrypt": "^5.1.1", "bullmq": "^5.41.3", diff --git a/apps/server/src/app.module.ts b/apps/server/src/app.module.ts index f8fd1071..2f6ae5d2 100644 --- a/apps/server/src/app.module.ts +++ b/apps/server/src/app.module.ts @@ -14,9 +14,11 @@ import { EventEmitterModule } from '@nestjs/event-emitter'; import { HealthModule } from './integrations/health/health.module'; import { ExportModule } from './integrations/export/export.module'; import { ImportModule } from './integrations/import/import.module'; +import { SentryModule } from "@sentry/nestjs/setup"; @Module({ imports: [ + SentryModule.forRoot(), CoreModule, DatabaseModule, EnvironmentModule, diff --git a/apps/server/src/collaboration/server/collab-app.module.ts b/apps/server/src/collaboration/server/collab-app.module.ts index 5f3ddcbb..cdd36883 100644 --- a/apps/server/src/collaboration/server/collab-app.module.ts +++ b/apps/server/src/collaboration/server/collab-app.module.ts @@ -8,9 +8,11 @@ import { QueueModule } from '../../integrations/queue/queue.module'; import { EventEmitterModule } from '@nestjs/event-emitter'; import { HealthModule } from '../../integrations/health/health.module'; import { CollaborationController } from './collaboration.controller'; +import { SentryModule } from "@sentry/nestjs/setup"; @Module({ imports: [ + SentryModule.forRoot(), DatabaseModule, EnvironmentModule, CollaborationModule, diff --git a/apps/server/src/collaboration/server/collab-main.ts b/apps/server/src/collaboration/server/collab-main.ts index 489ad943..309ea3e2 100644 --- a/apps/server/src/collaboration/server/collab-main.ts +++ b/apps/server/src/collaboration/server/collab-main.ts @@ -1,3 +1,4 @@ +import "./common/sentry/instrument"; import { NestFactory } from '@nestjs/core'; import { CollabAppModule } from './collab-app.module'; import { diff --git a/apps/server/src/common/sentry/instrument.ts b/apps/server/src/common/sentry/instrument.ts new file mode 100644 index 00000000..39870841 --- /dev/null +++ b/apps/server/src/common/sentry/instrument.ts @@ -0,0 +1,16 @@ +import * as Sentry from '@sentry/nestjs'; +import { nodeProfilingIntegration } from '@sentry/profiling-node'; +import { envPath } from '../helpers'; +import * as dotenv from 'dotenv'; +dotenv.config({ path: envPath }); + +if (process.env.SENTRY_DSN) { + Sentry.init({ + dsn: process.env.SENTRY_DSN, + integrations: [ + nodeProfilingIntegration(), + ], + tracesSampleRate: 1.0, + profilesSampleRate: 1.0, + }); +} diff --git a/apps/server/src/main.ts b/apps/server/src/main.ts index 1d51644e..fe71e61f 100644 --- a/apps/server/src/main.ts +++ b/apps/server/src/main.ts @@ -1,3 +1,4 @@ +import "./common/sentry/instrument"; import { NestFactory } from '@nestjs/core'; import { AppModule } from './app.module'; import {