Repository navigation
feat: add reactive command support for lettuce-4.0 instrumentation - #19071
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds tracing for Lettuce 4.0 reactive Redis commands (RxJava-based com.lambdaworks.redis API). It complements the existing async and sync instrumentation in the lettuce-4.0 javaagent module. Spans are started when a reactive command is dispatched (ReactiveCommandDispatcher.call) and ended when the underlying ObservableCommand terminates (complete / cancel / completeExceptionally). The original caller context is stashed via COMMAND_CONTEXT_KEY and restored while terminal callbacks run, so spans created inside subscriber callbacks link to the caller's context.
The implementation closely mirrors the established async instrumentation in the same module (LettuceAsyncCommandInstrumentation) and the reactive instrumentation in lettuce-5.0. The flow is internally consistent: non-response commands (e.g. SHUTDOWN) are ended early in the dispatch advice, and the terminal advice's endReactiveCommand short-circuits for those to avoid double-ending; command-level errors are extracted from the command output, and cancellation optionally records the experimental lettuce.command.cancelled attribute. The context.makeCurrent() in the terminal advice is NPE-safe because the context is only stored when COMMAND_CONTEXT_KEY is present.
Changes:
- Add
LettuceReactiveCommandsInstrumentation(instrument dispatcher constructor +call) andLettuceReactiveCommandInstrumentation(instrumentObservableCommandconstructor + terminal methods), registered inLettuceInstrumentationModule. - Add
InstrumentationPoints.endReactiveCommandto finalize reactive spans, mapping output/throwable errors and recording cancellation. - Add
LettuceReactiveClientTestcovering subscribers, lambdas, flux publishers, blocking/async subscribers, and no-span cases.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
LettuceReactiveCommandsInstrumentation.java |
New instrumentation that stores caller context on the dispatcher and starts the span on call, restoring scope and ending non-response spans on exit. |
LettuceReactiveCommandInstrumentation.java |
New instrumentation that saves the span context on ObservableCommand and ends the span + restores parent context on terminal methods. |
InstrumentationPoints.java |
Adds endReactiveCommand to end reactive spans with error/cancellation handling. |
LettuceInstrumentationModule.java |
Registers the two new reactive instrumentations. |
LettuceReactiveClientTest.java |
New test suite for reactive command tracing, mirroring the lettuce-5.0 reactive tests. |
|
Thank you for your contribution @YaoYingLong! 🎉 We would like to hear from you about your experience contributing to OpenTelemetry by taking a few minutes to fill out this survey. |
Adds tracing support for Lettuce 4.0 reactive Redis commands.
The new instrumentation starts spans when reactive commands are dispatched and ends them when the underlying reactive command completes, fails, or is cancelled. It also preserves the parent context for reactive callbacks so spans created inside subscribers are linked to the original caller context.