use PerformanceMonitorInterceptor from Spring with Axon

Hi,

I try to use PerformanceMonitorInterceptor as exampled here: https://www.baeldung.com/spring-performance-logging#performancemonitorinterceptor but when I allow its pointcut to check all packages (including @Aggregate and all Axon classes) I get:

Error starting ApplicationContext. To display the conditions report re-run your application with ‘debug’ enabled.
16291 [main] ERROR o.s.boot.SpringApplication - Application run failed
java.lang.IllegalStateException: Failed to execute ApplicationRunner
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:786)
at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:773)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1242)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1230)
at com.test.Application.main(Application.java:9)
Caused by: org.axonframework.eventsourcing.IncompatibleAggregateException: Aggregate identifier must be non-null after applying an event. Make sure the aggregate identifier is initialized at the latest when handling the creation event.

during application start. I’m not sure what is the reason. Did anyone had such issue?

Hi,

the underlying issue is that this interceptor creates proxies of beans. Axon isn’t aware that some classes may be proxies, and uses field inspection to get certain values. In proxies, these are all null, because all the proxy does is relay method invocations; it doesn’t keep state.

You can use Message Handler Interceptors in Axon to achieve the same thing. There is an Axon-micrometer module that gives you a lot of metrics out of the box. When using Spring Boot, adding the dependency should be enough.

Hope this clarifies it.
Cheers,

Allard

twitter-icon_128x128.png