Open dkroehan opened 2 days ago
You can try register your own TimedAspect
bean with @Order(Ordered.HIGHEST_PRECEDENCE)
to backoff auto configured bean.
While reviewing https://github.com/spring-projects/spring-boot/pull/42450, I formed the opinion that this is quite subjective and I suspect that users will be able to make compelling cases for either ordering. To fix this, I think we may have to make the ordering configurable so that the advice from the TimedAspect
that Boot configures can be made to run before or after Framework's advice for @Transactional
.
There's other advice that users may or may not want to be including in the timing such as Spring Security's advice for method-based security. Anything that we do here looks like it will require changes across multiple projects. As part of that, I wonder if it's worth considering support for some relative ordering so that we don't have to rely on magic numbers across those projects.
I use micrometer in a Spring Boot application to measure the execution time of a method. Given the following (Kotlin) method:
I would expect that the
@Timed
annotation measures the total time that the method execution takes including the@Transactional
handling. I compared it to measuring the time outside, as in the following example:Since the time measuring is different I did some debugging and found out that the underlying
io.micrometer.core.aop.TimedAspect
runs after the@Transactional
processing, which means the order is as follows:What I would like to achieve is the following order:
I already opened an issue at micrometer: https://github.com/micrometer-metrics/micrometer/issues/5235, but they pointed me to the spring-framework issue tracker.
I already tried to use
@DeclarePrecedence
like this +@EnableAspectJAutoProxy
on the@SpringBootApplication
class, but it had no effect.