Support micrometer-context-propagation
micrometer-context-propagation is now available. https://github.com/micrometer-metrics/context-propagation
And the reactor supports micrometer-context-propagation. https://spring.io/blog/2023/03/30/context-propagation-with-project-reactor-3-unified-bridging-between-reactive
Currently, Armeria provides RequestContextHooks, which could be replaced by providing an extension to micrometer-context-propagation.
like this:
// Sorry, I wrote it in kotlin.
class ArmeriaRequestContextAccessor : ThreadLocalAccessor<RequestContext> {
override fun key(): Any {
return KEY
}
override fun getValue(): RequestContext? {
return RequestContextUtil.get()
}
override fun setValue(value: RequestContext) {
RequestContextUtil.getAndSet<RequestContext>(value)
}
override fun setValue() {
// NOOP
}
override fun restore(previousValue: RequestContext) {
RequestContextUtil.getAndSet<RequestContext>(previousValue)
}
override fun restore() {
RequestContextUtil.pop()
}
companion object {
val KEY = ArmeriaRequestContextAccessor::class.java
}
}
Then, users can execute the following code.
fun main(args: Array<String>) {
ContextRegistry.getInstance().registerThreadLocalAccessor(ArmeriaRequestContextAccessor())
Hooks.enableAutomaticContextPropagation()
// run application
}
From the above article, it seems to me that the performance aspect has been devised. ( I haven't measured it but...
Took a quick look through the API/source and looks promising! 👍
If I understood correctly, this can be a much simpler solution over RequestContextHooks
@chickenchickenlove will work on it :smile:
wow, sounds good. I think it will probably improve performance.
( Sorry I didn't contribute with a pull request. haha