micrometer-metrics/micrometer

Timer API does not support Kotlin suspend function (coroutines)

Open

#4,455 创建于 2023年12月7日

在 GitHub 查看
 (4 评论) (6 反应) (0 负责人)Java (935 fork)batch import
enhancementhelp wantedkotlin

仓库指标

Star
 (4,220 star)
PR 合并指标
 (平均合并 1天 21小时) (30 天内合并 100 个 PR)

描述

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.

贡献者指南