Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timer API does not support Kotlin suspend function (coroutines) #4455

Open
AleksanderBrzozowski opened this issue Dec 7, 2023 · 2 comments
Labels
enhancement A general enhancement help wanted An issue that a contributor can help us with kotlin
Milestone

Comments

@AleksanderBrzozowski
Copy link
Contributor

Please describe the feature request.

For standard (non suspend functions) it is possible to use record function to measure method invocation time:

Timer.builder("method.timed")
            .register(meterRegistry)
            .record { fn() } // fn() is a standard, non suspend function

However, it is not possible to call a suspend function from within record block:

Timer.builder("method.timed")
            .register(meterRegistry)
            .record { suspendFn() } // Suspension functions can be called only within coroutine body

The support for suspend functions should be added to the library.

Rationale
Suspend functions are popular for non-blocking API, and it is currently not possible to measure time needed to call suspend functions without having a custom function to record the time.

Additional context
Maybe this could be added as a extension function to the Timer interface.

@micheljung
Copy link

I'd love to see this, too. See also: https://techlab.bol.com/en/blog/measuring-execution-time-in-kotlin-coroutines/

@shakuzen shakuzen added this to the 1.x milestone Oct 11, 2024
@shakuzen shakuzen added the help wanted An issue that a contributor can help us with label Oct 11, 2024
@shakuzen
Copy link
Member

We would review a pull request to add this functionality. There is a similar pull request open now for adding an extension function to Observation to support suspend functions - see #4823.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement A general enhancement help wanted An issue that a contributor can help us with kotlin
Projects
None yet
Development

No branches or pull requests

3 participants