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

Add optional support for Micrometer Context Propagation #4187

Open
bclozel opened this issue Jul 19, 2024 · 0 comments
Open

Add optional support for Micrometer Context Propagation #4187

bclozel opened this issue Jul 19, 2024 · 0 comments

Comments

@bclozel
Copy link

bclozel commented Jul 19, 2024

This enhancement request comes from the Spring Framework team with spring-projects/spring-framework#32165 as background.

Use case

Right now, the kotlinx-coroutines-reactor library copies the Reactor context as a key under the Coroutine Context.
The Spring community has requested many times the transparent propagation of contexts between threadlocals, reactive and coroutine. This lead to the creation of the Micrometer Context Propagation library, a zero dependency small library for this very purpose.

The Spring team received multiple reports of contexts not being propagated as expected between Coroutines and ThreadLocal/Reactor. This feature is required by observability instrumentations that Spring projects provide for metrics and traces in applications.

See here for a detailed explanation of the missing bits when using Coroutines in a Spring application that expects tracing: spring-projects/spring-framework#32165 (comment)

The Shape of the API

We have refined and tested an implementation that makes all elements work together as expected by Spring+Kotlin users: spring-projects/spring-framework#32165 (comment)

Prior Art

As explained in this comment, we have considered moving this utility class to several places, unsuccessfully so far. This requires org.jetbrains.kotlinx:kotlinx-coroutines-reactor (a required dependency) and io.micrometer:context-propagation (as an optional dependency) to work.

Kotlin users would still need to opt-in and use this PropagationContextElement, but I think this aligns nicely with the Kotlin developers' expectations.

Do you think this PropagationContextElement class belongs in org.jetbrains.kotlinx:kotlinx-coroutines-reactor? Note that reactor-core itself already has deep (but optional) integrations with the context propagation library.

Thanks!

cc'ing @sdeleuze on this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants