Fix(Tracing): Ensure context is ready before observation creation #3407
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
Observationwas not being set on theLettuceObservationContextbefore the childObservationwas created. This could preventObservationPredicateimplementations from correctly accessing parent context details.Problem:
When creating a child span from a parent trace context, the parent
Observationwas being associated with the newObservationobject after its creation. This meant that theLettuceObservationContextwas not aware of the parent during the creation process, and anyObservationPredicatelogic 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 theLettuceObservationContextwith 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: TheRedisObservationenum 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:formattarget. Don’t submit any formatting related changes.