npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nest-raven

v10.1.0

Published

Sentry Raven Module for Nest Framework

Downloads

132,276

Readme

Description

This is a sentry module for Nest.

This package is no longer based on deprecated raven module, but rather on new stable @sentry/node module.

Should i use this for large projects?

This is not a solution for all cases and large applications, just a quick starter that covers the common rest/graphql capturing (the basics). You might want deeper integration with Sentry, which means you can still use this to cover the rest/graphql error capture, but you will have to use the rest of Sentry SDK to cover other cases.

For really large projects, you might have to take this library as an example of how to integrate sentry with NestJS, and write your custom integration instead.

Installation

$ npm i --save nest-raven

Quick Start

Include Module

For Module to work you need to setup Sentry SDK yourself, this should be done in your main.ts file where you initialize the NestJS application.

app.module.ts

@Module({
  imports: [RavenModule],
})
export class ApplicationModule implements NestModule {}

Using Interceptor

app.controller.ts

  @UseInterceptors(new RavenInterceptor())
  @Get('/some/route')
  public async someRoute() {
    ...
  }

With this setup, sentry will pick up all exceptions (even 400 types).

Global

If you want to set up interceptor as global, you have to follow Nest instructions here. Something like this. This only works for Controllers not for Gateways (limitation by NestJS):

app.module.ts

import { APP_INTERCEPTOR } from '@nestjs/core';

@Module({
  imports: [RavenModule],
  providers: [
    {
      provide: APP_INTERCEPTOR,
      useValue: new RavenInterceptor(),
    },
  ],
})
export class ApplicationModule {}

Filters

Sometimes we don't want to catch all exceptions but only 500 or those that we didn't handle properly. For that we can add filters on interceptor to filter out good exceptions.

app.controller.ts

  @UseInterceptors(new RavenInterceptor({
    filters: [
        // Filter exceptions of type HttpException. Ignore those that
        // have status code of less than 500
        { type: HttpException, filter: (exception: HttpException) => 500 > exception.getStatus() }
    ],
  }))
  @Get('/some/route')
  public async someRoute() {
    ...
  }

Transformers

It may be useful to add some extra data to the Sentry's context before sending the payload. Adding some request-related properties for instance. To achieve this we can add scope transformers on interceptor to injecte some data dynamically.

app.controller.ts

  @UseInterceptors(new RavenInterceptor({
    transformers: [
        // Add an extra property to Sentry's scope
        (scope: Scope, context: ExecutionContext) => {
          const req = context.switchToHttp().getRequest<Request>();
          scope.addExtra('important query', req.query.important_query)
          scope.addExtra('important key', 'useful value');
        }
    ],
  }))
  @Get('/some/route')
  public async someRoute() {
    ...
  }

Additional data

Interceptor automatically adds req and req.user (as user) to additional data.

Other additional data can be added for each interceptor.

  • tags
  • extra
  • fingerprint
  • level

app.controller.ts

import { Severity } from '@sentry/node';

  @UseInterceptors(new RavenInterceptor({
    tags: {
      type: 'fileUpload',
    },
    level: Severity.Warning,
  }))
  @Get('/some/route')
  public async someRoute()
    ...
  }

Websockets

Note: Websockets ignore Global interceptors.

It will add ws_client and ws_data extras.

app.gateway.ts

  @UseInterceptors(new RavenInterceptor())
  @SubscribeMessage('message_name')
  public someMessage(client, data: string): string {
    ...
  }

GraphQL

It will add fieldName and args extras.

app.gateway.ts

  @Mutation()
  @UseInterceptors(new RavenInterceptor())
  async upvotePost(@Args('postId') postId: number) {
    ...
  }