ssut / nestjs-sqs

A project to make SQS easier to use within NestJS, with decorator-based handling and seamless NestJS-way integration.
MIT License
215 stars 53 forks source link

@SqsMessageHandler() is not being added to Nest's execution context #10

Closed MitchWeber closed 3 years ago

MitchWeber commented 3 years ago

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()));
  }
}
ssut commented 3 years ago

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.