Skip to content

Commit

Permalink
Feat: Sentry Integration
Browse files Browse the repository at this point in the history
  • Loading branch information
J-Hoplin committed Jan 17, 2024
1 parent 52ceafe commit 0f4a538
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/filter/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './sentry.filter';
11 changes: 11 additions & 0 deletions src/filter/sentry.filter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { ArgumentsHost, Catch } from '@nestjs/common';
import { BaseExceptionFilter } from '@nestjs/core';
import * as Sentry from '@sentry/node';

@Catch()
export class SentryFilter extends BaseExceptionFilter {
catch(exception: any, host: ArgumentsHost): void {
Sentry.captureException(exception);
super.catch(exception, host);
}
}
16 changes: 15 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import { ValidationPipe } from '@nestjs/common';
import { NestFactory } from '@nestjs/core';
import { HttpAdapterHost, NestFactory } from '@nestjs/core';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { InitializeAdmin } from './admin-init';
import { AppModule } from './app.module';
import { SentryFilter } from './filter';
import * as Sentry from '@sentry/node';

async function bootstrap() {
const app = await NestFactory.create(AppModule);

// Get Express http adapter
const { httpAdapter } = app.get(HttpAdapterHost);

app.enableCors();
app.useGlobalPipes(
// Docs: https://docs.nestjs.com/techniques/validation
Expand Down Expand Up @@ -35,6 +41,14 @@ async function bootstrap() {
explorer: true,
});

// Sentry
Sentry.init({
dsn: process.env.SENTRY_DSN,
tracesSampleRate: 1.0,
profilesSampleRate: 1.0,
});
app.useGlobalFilters(new SentryFilter(httpAdapter));

await app.listen(process.env.PORT || 3000);
}
bootstrap();

0 comments on commit 0f4a538

Please sign in to comment.