9

What is the right way to create an aspect around Kotlin suspended function?

From my observation, Micrometer's @Timed aspect does work with them, but shows incorrect result - looks like it measures time between method invocation and suspension, not the full time spent in the method (which should include post-suspension period)

Example of what I'd like to achieve:

@CoroutineTimer
suspend fun dbCall() {
    repository.someQuery().awaitFirst() // suspension point
}

In this case I'd like to know the full time spent on dbCall function, marked with a custom @CoroutineTimer annotation. Is there a way do so?

Pedro Carneiro
  • 103
  • 1
  • 10
silent-box
  • 1,649
  • 3
  • 21
  • 40

0 Answers0