nestjs-sentry
nestjs-sentry copied to clipboard
[bug]: Sentry does not capture exceptions
Input Code?
I'm trying to configure Sentry for nestjs application.
I do not want to handle errors manually by using ::captureException.
Instead, I want to send all my uncaught errors to the sentry.
@Module({
imports: [
SentryModule.forRootAsync({
imports: [ConfigModule],
useFactory: function (configService: ConfigService) {
return {
dsn: configService.get<string>('SENTRY_DSN'),
environment: process.env.NODE_ENV,
};
},
inject: [ConfigService],
}),
ConfigModule.forRoot({ isGlobal: true }),
],
})
export class AppModule implements OnApplicationBootstrap {
onApplicationBootstrap(): never {
setTimeout(() => {
throw new Error('Test error');
}, 0);
}
}
Current and expected behavior
Current: Command failed with exit code 1 with no exception sent to sentry Expected: Command failed with exit code 1 and exception sent to sentry
Environment
- @nestjs/core: 8.2.5
- @nestjs/common: 8.2.5
- @nestjs/config: 1.1.6
- @ntegral/nestjs-sentry: 3.0.7
Node version — 16.13.1
Possible solution
We need to flush the sentry and wait before we terminate the process.
// lib/sentry.service.ts
(Sentry.getCurrentHub().getClient<Client<Options>>() as Client<Options>).captureException(err);
await Sentry.flush(); // <----- flush here
process.exit(1);
I don't think you're using the interceptor so nothing will get reported automatically. Look at the second message in this issue: https://github.com/ntegral/nestjs-sentry/issues/62