When I want to use a NestJs interceptor (using standard NestJs interceptors) to wrap the whole message handler method into an transaction the interceptor never gets executed because the @SqsMessageHandler()-annotation is not registered with NestJs.
@Injectable()
export class CustomerImportMessageHandler {
private logger = new Logger(CustomerImportMessageHandler.name);
@SqsMessageHandler(Queue.CustomerImport)
@UseInterceptors(SentryTransactionInterceptor)
public async handleMessage(message: SQS.Message) {
// do whatever you have to do.
}
}
@Injectable()
export class SentryTransactionInterceptor implements NestInterceptor {
// Never gets executed.
intercept(context: ExecutionContext, next: CallHandler): Observable<any> {
const transaction = Sentry.startTransaction({
name: context.getClass().name,
});
return next.handle().pipe(tap(() => transaction.finish()));
}
}
I don't think nestjs-sqs should support this because NestJs' interceptor or execution context is made for and valid for the controller layer, not service(= provider) layer.
When I want to use a NestJs interceptor (using standard NestJs interceptors) to wrap the whole message handler method into an transaction the interceptor never gets executed because the
@SqsMessageHandler()
-annotation is not registered with NestJs.