I have created a cron setup on a service, and I have the following Interceptor setup for Sentry.io profiler:
@Injectable()
export class SentryProfilerInterceptor implements NestInterceptor {
intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
// Start a new Sentry transaction for profiling
const transaction = Sentry.startTransaction({
op: context.getClass().name,
name: context.getHandler().name,
});
// Set transaction on scope to associate with errors and get included span instrumentation
// If there's currently an unfinished transaction, it may be dropped
Sentry.getCurrentScope().setSpan(transaction);
// Execute the request handler
return next.handle().pipe(
tap({
next: () => {
transaction.setStatus(Sentry.spanStatusfromHttpCode(200));
transaction.finish();
},
error: () => {
transaction.setStatus(Sentry.spanStatusfromHttpCode(500));
transaction.finish();
},
}),
);
}
}
I want to record the performance on my cron, but it seems that I cannot use interceptor on services?