[reactor-optional] Implement trace context propagation without hard dependency on Reactor - #3708
Conversation
…thout hard dependency to reactor in tracexontextprovider
There was a problem hiding this comment.
Pull request overview
This PR refactors reactive trace-context propagation to avoid relying on Reactor ContextView/Mono-based resolution at the TraceContextProvider call site by introducing a Map-based async context lookup and adapting Reactor context to that interface.
Changes:
- Add
TraceContextProvider.getTraceContextAsync(Map<Object, Object>)(returnsSupplier<TraceContext>) and deprecategetTraceContextLater(). - Implement
getTraceContextAsyncfor Brave and Micrometer tracing providers to resolve trace context from the provided map (with deliberate no-ThreadLocal fallback when async context is present). - Update reactive command tracing (
AbstractRedisReactiveCommands.withTraceContext) to resolve trace context viadeferContextual+ContextViewMapAdapter.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
src/main/java/io/lettuce/core/tracing/TraceContextProvider.java |
Introduces Map-based async context lookup API and deprecates Reactor-Mono method. |
src/main/java/io/lettuce/core/tracing/BraveTracing.java |
Adds getTraceContextAsync implementation for Brave context lookup. |
src/main/java/io/lettuce/core/tracing/MicrometerTracing.java |
Adds getTraceContextAsync implementation for Micrometer context lookup. |
src/main/java/io/lettuce/core/AbstractRedisReactiveCommands.java |
Adapts Reactor ContextView to Map and switches reactive trace context resolution to the new API. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
a-TODO-rov
left a comment
There was a problem hiding this comment.
The approach LGTM - this is the way !
I think we should follow the same approach on all public APIs, directly exposing reactive - simple plain java foundation (async based) for the reactive implementation to adapt.
Minor comments to become production ready:
- javadoc
- tests
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
There are 2 total unresolved issues (including 1 from previous review).
Reviewed by Cursor Bugbot for commit 76aeb15. Configure here.
Co-authored-by: Copilot <copilot@github.com>
11ae917
into
redis:feature/reactor-optional-1

Introduces a new
getTraceContextAsyncmethod onTraceContextProviderthat accepts a plainMap<Object, Object>instead of relying on Reactor'sMono-based deferred resolution. This removes the hard dependency on Reactor from theTraceContextProviderinterface while still supporting trace context propagation in reactive command flows. A lightweightContextViewMapAdapterbridges Reactor'sContextViewto theMapinterface at the call site.Changes
TraceContextProvider– AddedgetTraceContextAsync(Map<Object, Object>)default method that returns aSupplier<TraceContext>. Deprecated the existinggetTraceContextLater()method.BraveTracing– ImplementedgetTraceContextAsyncto look upSpanorTraceContextfrom the provided map, intentionally skipping ThreadLocal fallback in async contexts.MicrometerTracing– ImplementedgetTraceContextAsyncto look upObservation,TraceContext, orObservationThreadLocalAccessor.KEYfrom the provided map, with the same ThreadLocal-skip policy.AbstractRedisReactiveCommands– AddedContextViewMapAdapter(a read-onlyAbstractMapbacked by Reactor'sContextView) and replacedwithTraceContext()with an implementation that usesdeferContextual+getTraceContextAsyncfor non-blocking trace context resolution.Note
Medium Risk
Changes how reactive tracing context is resolved and propagated (new async context API and updated
withTraceContext()), which can affect span parentage/trace continuity across reactive flows. Scope is contained to tracing integration, with new integration tests reducing regression risk.Overview
Updates trace-context propagation to avoid a hard Reactor dependency by introducing
TraceContextProvider#getTraceContextAsync(Map)(returning aSupplier<TraceContext>) and deprecatinggetTraceContextLater().Reactive command tracing now resolves parent context via Reactor
ContextViewusing a lightweightContextViewMapAdapter, callinggetTraceContextAsyncduringdeferContextualinAbstractRedisReactiveCommands#withTraceContext().Adds async-context implementations for Brave and Micrometer providers (explicitly not falling back to ThreadLocals when an async context map is present), plus new integration tests covering async (
connection.async()) and reactive (contextWrite) tracing flows and verifying emitted spans/tags and parent/trace IDs.Reviewed by Cursor Bugbot for commit 208dbb9. Bugbot is set up for automated code reviews on this repo. Configure here.