Fix(Tracing): Ensure context is ready before observation creation #3407
+23
−14
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.
This commit fixes an issue in the Micrometer tracing integration where the parent
Observation
was not being set on theLettuceObservationContext
before the childObservation
was created. This could preventObservationPredicate
implementations from correctly accessing parent context details.Problem:
When creating a child span from a parent trace context, the parent
Observation
was being associated with the newObservation
object after its creation. This meant that theLettuceObservationContext
was not aware of the parent during the creation process, and anyObservationPredicate
logic that relied on the parent's presence in the context would fail.Solution:
To address this, the following changes were made:
MicrometerTracer.nextSpan(…)
: The logic has been updated to first populate theLettuceObservationContext
with the parentObservation
. The observation is then created using this fully-populated context.MicrometerTracer.createObservation(…)
: The observation factory method has been updated to use a more suitable Micrometer Observation API overload, which accepts both a primary and a default convention for better alignment with Micrometer's practices.RedisObservation.java
: TheRedisObservation
enum now implements thegetDefaultConvention()
method, which is necessary to support the updated observation creation logic.These changes ensure that the observation context is complete before the observation is created, making the tracing integration more robust and aligned with Micrometer's intended usage.
Closes #3406
Make sure that:
mvn formatter:format
target. Don’t submit any formatting related changes.