Registry / observability / nest-raven

nest-raven

JSON →
library10.1.0jsnpmunverified

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.

npm install nest-raven
INSTALL
IMPORT
SIG · NEST-RAVEN
N
nest-raven
observabilityjavascriptv10.1.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

RavenModule
import { RavenModule } from 'nest-raven';
const { RavenModule } = require('nest-raven');
Use ES Module imports. CommonJS `require` is generally not idiomatic for modern NestJS applications, which are typically TypeScript and ESM-first.
RavenInterceptor
import { RavenInterceptor } from 'nest-raven';
import RavenInterceptor from 'nest-raven';
RavenInterceptor is a named export, not a default export.
APP_INTERCEPTOR
import { APP_INTERCEPTOR } from '@nestjs/core';
While used with `nest-raven`, this is a core NestJS token for registering global interceptors, not directly from `nest-raven`.

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.

import { NestFactory } from '@nestjs/core'; import { Module, NestModule, UseInterceptors, Get, HttpException, Controller } from '@nestjs/common'; import { APP_INTERCEPTOR } from '@nestjs/core'; import { RavenModule, RavenInterceptor } from 'nest-raven'; import * as Sentry from '@sentry/node'; // Initialize Sentry SDK early in your application lifecycle Sentry.init({ dsn: process.env.SENTRY_DSN ?? 'YOUR_SENTRY_DSN_HERE', tracesSampleRate: 1.0, }); @Controller() class AppController { @UseInterceptors(new RavenInterceptor({ filters: [ { type: HttpException, filter: (exception: HttpException) => exception.getStatus() < 500 } ], // Example transformer to add custom data to Sentry scope // transformer: (scope, context) => { // const http = context.getType() === 'http' ? context.switchToHttp() : null; // if (http) { // const request = http.getRequest(); // scope.setExtra('customRequestData', { url: request.url, method: request.method }); // } // return scope; // } })) @Get('/error') public async triggerError() { throw new Error('This is a test error to be captured by Sentry!'); } @Get('/client-error') public async clientError() { throw new new HttpException('This is a client error (400 level)', 400); } @Get('/server-error') public async serverError() { throw new new HttpException('This is a server error (500 level)', 500); } } @Module({ imports: [RavenModule], controllers: [AppController], providers: [ { provide: APP_INTERCEPTOR, useValue: new RavenInterceptor(), // Global interceptor without filters }, ], }) export class ApplicationModule {} async function bootstrap() { const app = await NestFactory.create(ApplicationModule); await app.listen(3000); console.log('Application is running on: http://localhost:3000'); console.log('Visit /error, /client-error, /server-error to trigger errors.'); } bootstrap();
Debug
Known issues
breakingVersion 10.0.0 of `nest-raven` requires NestJS v10.0.0 or higher. Ensure your `@nestjs/common` and other core NestJS packages are updated accordingly.
fix
Update all `@nestjs/*` peer dependencies to `^10.0.0` or newer versions.
affects: >=10.0.0
breakingVersion 8.0.0 of `nest-raven` introduced a breaking change by upgrading to NestJS v8. This required corresponding updates in your NestJS application dependencies.
fix
Ensure all `@nestjs/*` peer dependencies are updated to `^8.0.0`.
affects: >=8.0.0 <9.0.0
gotchaThe Sentry SDK (`@sentry/node`) must be initialized manually using `Sentry.init()` in your application's `main.ts` file or similar entry point, *before* NestJS application bootstrap. `nest-raven` does not handle this initialization.
fix
Add `Sentry.init({ dsn: 'YOUR_SENTRY_DSN' });` at the top level of your `main.ts`.
affects: >=1.0.0
gotchaWhen `RavenInterceptor` is applied globally using `APP_INTERCEPTOR`, it only captures exceptions from HTTP controllers. It does not provide error capturing for WebSockets (Gateways) due to a limitation in how NestJS applies global interceptors.
fix
For WebSocket Gateways, implement a custom exception filter or apply `RavenInterceptor` directly to the Gateway methods using `@UseInterceptors(new RavenInterceptor())` if supported by NestJS for that specific context.
affects: >=1.0.0
gotchaThis module is described as a 'quick starter' and may not be sufficient for large applications requiring deep Sentry integration beyond basic REST/GraphQL error capturing. Custom Sentry integrations may be necessary.
fix
For complex scenarios, consider using this library as a guide and implementing a custom Sentry integration tailored to your specific application architecture.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Sentry SDK is not initialized, call Sentry.init() first.
The `@sentry/node` SDK was not initialized with `Sentry.init()` before the NestJS application started or before an error occurred.
fix
Add `Sentry.init({ dsn: process.env.SENTRY_DSN });` to your `main.ts` file at the top, before `NestFactory.create()`.
Error: Can't resolve '@sentry/node' in 'node_modules/nest-raven/dist'
`@sentry/node` is a peer dependency of `nest-raven` but was not installed in your project.
fix
Install `@sentry/node`: `npm install @sentry/node` or `yarn add @sentry/node`.
TypeError: Cannot read properties of undefined (reading 'switchToHttp')
This error can occur in a custom `transformer` function if the `context` passed to it is not an HTTP context (e.g., from a GraphQL execution context) and the code assumes `switchToHttp()` is always available without checking.
fix
Safely check the context type within your transformer: `const http = context.getType() === 'http' ? context.switchToHttp() : null;`
Upgrade
Version history
10.1.0latest on npm
Audit
Dependencies
@nestjs/commonrequiredCore NestJS framework dependency, required for module and interceptor functionality.
@sentry/noderequiredThe underlying Sentry SDK for Node.js environments, essential for error reporting.
rxjsrequiredUsed internally by NestJS interceptors for reactive programming patterns.
Agent activity
10 hits · last 30 days
node
8
OpenAI (training)
2
Resources