I have Sentry setup which sort of works. I am trying to improve it and one of the issues is that I get his error rather randomly and I cannot catch what is happening to cause it.
I have Nest app, and call the forRoot
method in AppModule:
const rootDir = __dirname || process.cwd();
@Module({
imports: [
SentryModule.forRoot({
dsn: process.env.SENTRY_KEY,
tracesSampleRate: 0.1,
debug: true,
normalizeDepth: 0, //Avoid normalizing contexts to achieve better explainability
maxValueLength: 1024 * 10, //Increase maximum length of payload value to 10Kb
integrations: [
new RewriteFrames({
root: rootDir,
}) as any,
],
}),
],
controllers: [],
providers: [],
})
export class AppModule {
configure(consumer: MiddlewareConsumer): void {
consumer.apply(Sentry.Handlers.requestHandler()).forRoutes({
path: "*",
method: RequestMethod.ALL,
});
}
}
The setup is using a middleware:
@Injectable({ scope: Scope.REQUEST })
export class SentryInterceptor implements NestInterceptor {
constructor(private sentryService: SentryService) {}
intercept(context: ExecutionContext, next: CallHandler): Observable<GenericRecord> {
// start a child span for performance tracing
const span = this.sentryService.startChild({ op: `route handler` });
return next.handle().pipe(
catchError((error) => {
// capture the error, you can filter out some errors here
Sentry.captureException(error, this.sentryService.span?.getTraceContext());
// throw again the error
return throwError(() => error);
}),
finalize(() => {
span?.finish();
this.sentryService.span?.finish();
}),
);
}
}
My two main problems are:
1. I randomly get
Sentry Logger [error]: SentryError: SDK not enabled, will not capture event.
at new SentryError (/node_modules/@sentry/src/error.ts:9:5)
at NodeClient.BaseClient._processEvent (/node_modules/@sentry/src/baseclient.ts:543:34)
at NodeClient.BaseClient._captureEvent (/node_modules/@sentry/src/baseclient.ts:504:17)
at NodeClient.BaseClient.captureEvent (/node_modules/@sentry/src/baseclient.ts:163:12)
at NodeClient.captureEvent (/node_modules/@sentry/src/client.ts:84:30)
at Hub._invokeClient (/node_modules/@sentry/src/hub.ts:500:30)
at Hub.captureEvent (/node_modules/@sentry/src/hub.ts:264:10)
at Transaction.finish (/node_modules/src/transaction.ts:152:22)
at Subscription.<anonymous> (/dist/apps/api/webpack:/apps/api/src/sentry/sentry.interceptor.ts:29:34)
at Subscription.unsubscribe (/node_modules/rxjs/src/internal/Subscription.ts:92:22)
2. My errors get converted to 500 in Sentry