Skip to content

feat: add reactive command support for lettuce-4.0 instrumentation - #19071

Merged
trask merged 6 commits into
open-telemetry:mainfrom
YaoYingLong:feature/lettuce-4.0
Jun 25, 2026
Merged

trask merged 6 commits into
open-telemetry:mainfrom
YaoYingLong:feature/lettuce-4.0

Conversation

@YaoYingLong

Copy link
Copy Markdown
Contributor

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.

Copilot AI review requested due to automatic review settings June 24, 2026 08:00
@YaoYingLong
YaoYingLong requested a review from a team as a code owner June 24, 2026 08:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) and LettuceReactiveCommandInstrumentation (instrument ObservableCommand constructor + terminal methods), registered in LettuceInstrumentationModule.
  • Add InstrumentationPoints.endReactiveCommand to finalize reactive spans, mapping output/throwable errors and recording cancellation.
  • Add LettuceReactiveClientTest covering 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.

@trask trask left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a couple of naming suggestions

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.

@trask
trask merged commit c5fcc9e into open-telemetry:main Jun 25, 2026
95 checks passed
@otelbot

otelbot Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants