nestjs-sentry icon indicating copy to clipboard operation
nestjs-sentry copied to clipboard

Fix SentryInterceptorOptions request type

Open mjorgegulab opened this issue 2 years ago • 0 comments

Description:

I discovered a problem with the request type of SentryInterceptorOptions as it is defined as a boolean type and did not allow me to specify the keys to be removed from the request object as described in the sentry documentation.

Sentry Docs

With this fix, when you use the SentryInterceptor() you will have the option to specify the request fields that you want to extract from the request object. The following example extract only the headers from the request:

@Module({
  imports: [
    SentryModule.forRootAsync({
      imports: [ConfigModule],
      useFactory: async (configService: ConfigService) =>
        configService.get('SENTRY_CONFIG'),
      inject: [ConfigService],
    }),
  ],
  controllers: [AppController],
  providers: [
    {
      provide: APP_INTERCEPTOR,
      useFactory: () =>
        new SentryInterceptor({
          request: ['headers'],
        }),
    },
  ],
})
export class AppModule implements NestModule {}

Tests results:

Captura de pantalla 2023-01-23 a las 14 49 47


Sentry results:

Captura de pantalla 2023-01-23 a las 14 44 07

mjorgegulab avatar Jan 23 '23 14:01 mjorgegulab