Skip to content

Commit

Permalink
feat: Add Sentry error monitoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Maelstromeous committed May 25, 2024
1 parent a6f9cb2 commit a3668c8
Show file tree
Hide file tree
Showing 5 changed files with 632 additions and 3 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ps2alerts-api",
"version": "4.5.0",
"version": "4.6.0",
"description": "The API that powers PS2Alerts.com",
"author": "",
"private": true,
Expand Down Expand Up @@ -48,6 +48,8 @@
"@nestjs/terminus": "^9.2.1",
"@nestjs/typeorm": "^9.0.1",
"@nestjs/websockets": "^9.3.12",
"@sentry/node": "^8.4.0",
"@sentry/profiling-node": "^8.4.0",
"@types/cache-manager-ioredis": "^2.0.3",
"@types/cron": "^2.0.1",
"amqp-connection-manager": "^4.1.11",
Expand Down
2 changes: 1 addition & 1 deletion provisioning/dev/start.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
- name: "ps2alerts"
tty: true
ports:
- "3000"
- "3000:3000"
env:
NODE_ENV: "development"
VERSION: "12345"
Expand Down
17 changes: 17 additions & 0 deletions src/instrument.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Import with `const Sentry = require("@sentry/node");` if you are using CJS
import * as Sentry from '@sentry/node';
import {nodeProfilingIntegration} from '@sentry/profiling-node';

Sentry.init({
dsn: 'https://09b6521e230a7a987e3ca046f774760c@o4507319323262976.ingest.de.sentry.io/4507319628922960',
environment: process.env.NODE_ENV,
release: process.env.VERSION,
integrations: [
nodeProfilingIntegration(),
],
// Performance Monitoring
tracesSampleRate: 1.0, // Capture 100% of the transactions

// Set sampling rate for profiling - this is relative to tracesSampleRate
profilesSampleRate: 1.0,
});
8 changes: 7 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {NestFactory} from '@nestjs/core';
import {NestFactory, BaseExceptionFilter, HttpAdapterHost} from '@nestjs/core';
import {FastifyAdapter, NestFastifyApplication} from '@nestjs/platform-fastify';
import {RmqOptions, Transport} from '@nestjs/microservices';
import {ConfigService} from '@nestjs/config';
Expand All @@ -8,6 +8,8 @@ import {ValidationPipe} from '@nestjs/common';
import {TypeOrmFilter} from './filters/type-orm.filter';
import compression from '@fastify/compress';
import {fastifyHelmet} from '@fastify/helmet';
import './instrument.js';
import * as Sentry from '@sentry/node';

async function bootstrap(): Promise<void> {
const app = await NestFactory.create<NestFastifyApplication>(
Expand All @@ -20,6 +22,10 @@ async function bootstrap(): Promise<void> {
},
);

// Sentry stuff
const {httpAdapter} = app.get(HttpAdapterHost);
Sentry.setupNestErrorHandler(app, new BaseExceptionFilter(httpAdapter));

const config = app.get(ConfigService);

// Fastify stuff
Expand Down
Loading

0 comments on commit a3668c8

Please sign in to comment.