Skip to content

Consider relative ordering for AspectJ aspects #33595

Open
@dkroehan

Description

@dkroehan

I use micrometer in a Spring Boot application to measure the execution time of a method.
Given the following (Kotlin) method:

class MyClass(...) {

  @Timed(value = "my_timer")
  @Transactional
  fun doSomething() {
    // Some code that performs changes on the database
  }
}

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:

val start = System.nanoTime()
myClass.doSomething()
timer.record(System.nanoTime() - start, TimeUnit.NANOSECONDS)

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:

  1. Transaction start
  2. Time measurement starts
  3. Method body execution
  4. Time measurement stops
  5. Transaction commits

What I would like to achieve is the following order:

  1. Time measurement starts
  2. Transaction start
  3. Method body execution
  4. Transaction commits
  5. Time measurement stops

I already opened an issue at micrometer: micrometer-metrics/micrometer#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.

@Aspect
@DeclarePrecedence("TimedAspect, *")
public class TimedAspectPrecedence {

}

Metadata

Metadata

Assignees

No one assigned

    Labels

    in: dataIssues in data modules (jdbc, orm, oxm, tx)type: enhancementA general enhancement

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions