Adding @Counted annotation to method causes tests to fail

45 views Asked by At

I have an existing spring boot project that I need to add some metric collection to, using Micrometer @Counted and @Timed annotations. It works just fine, as in I recieve metrics from the project, and I've added it to several other projects as well without any issues.

However when I run the tests on this particular project a bunch of them fail with this error:

java.lang.IllegalStateException: Required to bind 2 arguments, but only bound 1 (JoinPointMatch was NOT bound in invocation)

After some debugging and testing I found out it is the @Counted annotation that causes it to fail. Only having the @Timed works just fine. One method I'm adding the annotations to: (it fail no matter what method I add them to..)

@Override
@Trace(dispatcher = true)
@Counted(value = "methodname.counted")
@Timed(value = "methodname.timed")
public Mono<ResponseEntity<Flux<DTO>>> submit(String id, Flux<DTO> dto, ServerWebExchange exchange) {
....
}
1

There are 1 answers

0
Jonatan Ivanov On

The aspects for these annotations were not meant for using them with reactor. In the reactor use-case you should use the .tap operator, see: https://projectreactor.io/docs/core/release/reference/#_publisher_metrics

getMyFlux()
    .tap(Micrometer.metrics(registry))
    ...
    .subscribe();