Skip to content

Support micrometer-context-propagation #5145

@be-hase

Description

@be-hase

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...

Metadata

Metadata

Assignees

Labels

new featuresprintIssues for OSS Sprint participants

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions