{"library":"nest-raven","title":"NestJS Sentry Integration Module","description":"nest-raven is a module designed to seamlessly integrate Sentry error tracking into applications built with the NestJS framework. It replaces the deprecated `raven` package with the modern `@sentry/node` SDK, providing a robust solution for capturing exceptions. Currently stable at v10.1.0, the package typically releases updates in alignment with major NestJS framework versions, alongside regular dependency maintenance. While it offers a quick starter for common REST/GraphQL error capturing via interceptors and filters, the documentation advises that for large-scale projects requiring deeper Sentry integration beyond basic error handling, developers might consider using this library as a reference to implement a custom solution tailored to their specific needs. Its primary differentiators are its NestJS-native interceptor approach and a clear migration path from older Sentry integration methods.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install nest-raven"],"cli":null},"imports":["import { RavenModule } from 'nest-raven';","import { RavenInterceptor } from 'nest-raven';","import { APP_INTERCEPTOR } from '@nestjs/core';"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import { NestFactory } from '@nestjs/core';\nimport { Module, NestModule, UseInterceptors, Get, HttpException, Controller } from '@nestjs/common';\nimport { APP_INTERCEPTOR } from '@nestjs/core';\nimport { RavenModule, RavenInterceptor } from 'nest-raven';\nimport * as Sentry from '@sentry/node';\n\n// Initialize Sentry SDK early in your application lifecycle\nSentry.init({\n  dsn: process.env.SENTRY_DSN ?? 'YOUR_SENTRY_DSN_HERE',\n  tracesSampleRate: 1.0,\n});\n\n@Controller()\nclass AppController {\n  @UseInterceptors(new RavenInterceptor({\n    filters: [\n      { type: HttpException, filter: (exception: HttpException) => exception.getStatus() < 500 }\n    ],\n    // Example transformer to add custom data to Sentry scope\n    // transformer: (scope, context) => {\n    //   const http = context.getType() === 'http' ? context.switchToHttp() : null;\n    //   if (http) {\n    //     const request = http.getRequest();\n    //     scope.setExtra('customRequestData', { url: request.url, method: request.method });\n    //   }\n    //   return scope;\n    // }\n  }))\n  @Get('/error')\n  public async triggerError() {\n    throw new Error('This is a test error to be captured by Sentry!');\n  }\n\n  @Get('/client-error')\n  public async clientError() {\n    throw new new HttpException('This is a client error (400 level)', 400);\n  }\n\n  @Get('/server-error')\n  public async serverError() {\n    throw new new HttpException('This is a server error (500 level)', 500);\n  }\n}\n\n@Module({\n  imports: [RavenModule],\n  controllers: [AppController],\n  providers: [\n    {\n      provide: APP_INTERCEPTOR,\n      useValue: new RavenInterceptor(), // Global interceptor without filters\n    },\n  ],\n})\nexport class ApplicationModule {}\n\nasync function bootstrap() {\n  const app = await NestFactory.create(ApplicationModule);\n  await app.listen(3000);\n  console.log('Application is running on: http://localhost:3000');\n  console.log('Visit /error, /client-error, /server-error to trigger errors.');\n}\n\nbootstrap();","lang":"typescript","description":"This quickstart demonstrates how to initialize Sentry, integrate `RavenModule`, and use `RavenInterceptor` both locally on a route with filters (to ignore client errors) and globally for all controllers.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}