Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I’d like to add Micrometer Observation support for Spring users.
I previously added Micrometer Tracing support ( #205 ), but for the reasons described below, I’ve learned that adding Micrometer Observation support is preferable.
Why - TL;DR
Without using Micrometer Observation, we can’t achieve tracing in Spring-related asynchronous libraries (Reactor).
Why - Detail
Micrometer Observation is a library that sits “above” Micrometer and Micrometer Tracing.
By writing a single piece of instrumentation code, it enables Tracing / Metrics / Logging.
Micrometer Observation implements the instrumentation code for Micrometer Timer and Micrometer Tracing.
Since Spring Boot 3, Spring-related libraries generally use Micrometer Observation.
e.g.
Micrometer Observation has the concept of an Observation Context, and it stores the Tracing Context inside this Observation Context.
By propagating the Observation Context, the Tracing Context is propagated together, which makes tracing possible.
…This gets a bit nerdy from here, but there’s a library called Micrometer Context Propagation.
https://docs.micrometer.io/context-propagation/reference/
For reference, here’s an explanatory article I wrote:
https://dev.to/be-hase/about-micrometer-context-propagation-5gg9
In asynchronous libraries like Reactor, this Micrometer Context Propagation is used to propagate the Observation Context. (As a result, tracing works.)
In an environment that doesn’t use Micrometer Observation, the Observation Context doesn’t exist (in the current thread local), so tracing can’t work correctly.
What
This is implemented using Decaton’s TracingProvider / ProcessorTraceHandle / RecordTraceHandle.
In addition to unit tests, I also ran it in practice, and tracing works correctly.
(No issues with Reactor-based WebClient / Lettuce either.)
Downsides
By using Micrometer Observation, Micrometer Metrics like the following are also recorded. This slightly overlaps with Decaton’s existing metrics, but we’ll have to accept that.
It seems possible for users to avoid recording duplicate metrics by being creative on their side.
micrometer-metrics/micrometer#5467
What should we do with the existing Micrometer Tracing support?
Spring users should use the Micrometer Observation support added here.
I haven’t seen many libraries that use Micrometer Tracing alone, so if the maintenance cost feels high, it might be fine to remove it.