Skip to content

Remove noopScope() usage from vertx-redis-client advice#12008

Open
mcculls wants to merge 1 commit into
masterfrom
mcculls/cleanup-redis-advice
Open

Remove noopScope() usage from vertx-redis-client advice#12008
mcculls wants to merge 1 commit into
masterfrom
mcculls/cleanup-redis-advice

Conversation

@mcculls

@mcculls mcculls commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

What Does This Do

Remove AgentTracer.noopScope() usage from vertx-redis-client advice.

Increment/decrement the RedisAPI call-depth guard as the first statement of enter/exit advice instead of returning AgentTracer.noopScope() mid-method. This fixes a call-depth leak on the "parent span already REDIS_COMMAND" branch.

Also drops RedisAPICallAdvice's vestigial always-true boolean return and @Advice.Local in favor of returning the AgentScope directly via @Advice.Enter, guarding the now-possible null scope on close/cleanup.

Adds a regression test asserting the call-depth counter is balanced after each test.

Motivation

Aligns this advice with the common pattern of doing call-depth increment/decrement first, to avoid accidental imbalances.

This also removes a non-obvious use of AgentTracer.noopScope()

Contributor Checklist

Jira ticket: [PROJ-IDENT]

@mcculls mcculls added tag: no release notes Changes to exclude from release notes type: refactoring inst: redis Redis instrumentation labels Jul 20, 2026
@mcculls
mcculls requested a review from Copilot July 20, 2026 17:21
@mcculls

mcculls commented Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

Copilot AI left a comment

Copy link
Copy Markdown

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 updates the Vert.x Redis client (3.9) instrumentation advice to avoid using AgentTracer.noopScope() as a sentinel and to ensure the RedisAPI call-depth guard is always balanced, preventing call-depth leaks when spans are intentionally not created (e.g., when the parent span is already REDIS_COMMAND).

Changes:

  • Move CallDepthThreadLocalMap increment/decrement to the first statements of enter/exit advice in RedisSendAdvice and RedisFutureSendAdvice, returning null instead of noopScope().
  • Simplify RedisAPICallAdvice by returning the AgentScope directly via @Advice.Enter (and guarding the now-possible null scope), plus cleaning the context store via remove.
  • Add a regression assertion in the Vertx Redis test base to ensure the RedisAPI call-depth counter is balanced after each test.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
dd-java-agent/instrumentation/vertx/vertx-redis-client/vertx-redis-client-3.9/src/main/java/datadog/trace/instrumentation/vertx_redis_client/RedisSendAdvice.java Ensures call-depth is incremented/decremented in a balanced way regardless of early returns; removes noopScope() usage.
dd-java-agent/instrumentation/vertx/vertx-redis-client/vertx-redis-client-3.9/src/main/java/datadog/trace/instrumentation/vertx_redis_client/RedisFutureSendAdvice.java Same call-depth balancing and noopScope() removal for Future-based send path; simplifies connection-decoration logic accordingly.
dd-java-agent/instrumentation/vertx/vertx-redis-client/vertx-redis-client-3.9/src/main/java/datadog/trace/instrumentation/vertx_redis_client/RedisAPICallAdvice.java Returns AgentScope via @Advice.Enter instead of a vestigial boolean/local, guards null scope, and removes the stored handler from context on exit.
dd-java-agent/instrumentation/vertx/vertx-redis-client/vertx-redis-client-3.9/src/test/groovy/VertxRedisTestBase.groovy Adds a per-test call-depth regression assertion (but currently overrides base cleanup() without calling super).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4afb44d346

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@mcculls
mcculls force-pushed the mcculls/cleanup-redis-advice branch 4 times, most recently from 788d7b7 to 7330a9c Compare July 20, 2026 17:59
@datadog-prod-us1-6

datadog-prod-us1-6 Bot commented Jul 20, 2026

Copy link
Copy Markdown

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 69.73% (+12.44%)

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 9d3e164 | Docs | Datadog PR Page | Give us feedback!

@mcculls
mcculls force-pushed the mcculls/cleanup-redis-advice branch 2 times, most recently from 1b85dab to 78a595e Compare July 20, 2026 18:07
@mcculls

mcculls commented Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 78a595e7ff

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

@dd-octo-sts

dd-octo-sts Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

🟢 Java Benchmark SLOs — All performance SLOs passed

Suite Status
Startup 🟢 pass

SLO thresholds are defined here based on automatically generated metrics. A warning is raised when results are within 5% of the threshold.

PR vs. master results
Scenario Candidate master Δ (95% CI of mean)
startup:insecure-bank:iast:Agent 13.94 s 13.90 s [-0.5%; +1.0%] (no difference)
startup:insecure-bank:tracing:Agent 12.90 s 12.99 s [-1.4%; +0.1%] (no difference)
startup:petclinic:appsec:Agent 16.91 s 16.79 s [-0.2%; +1.6%] (no difference)
startup:petclinic:iast:Agent 16.87 s 16.98 s [-1.5%; +0.2%] (no difference)
startup:petclinic:profiling:Agent 16.77 s 16.81 s [-1.3%; +0.9%] (no difference)
startup:petclinic:sca:Agent 16.94 s 16.81 s [-0.1%; +1.6%] (no difference)
startup:petclinic:tracing:Agent 16.04 s 16.18 s [-1.7%; -0.1%] (maybe better)

Commit: 9d3e164c · CI Pipeline · Benchmarking Platform UI


Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion.

@mcculls
mcculls force-pushed the mcculls/cleanup-redis-advice branch from 78a595e to 44bfa56 Compare July 20, 2026 20:06
@mcculls

mcculls commented Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 44bfa56a85

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Increment/decrement the RedisAPI call-depth guard as the first statement of enter/exit
advice instead of returning AgentTracer.noopScope() mid-method. This fixes a call-depth
leak on the "parent span already REDIS_COMMAND" branch.

Also drops RedisAPICallAdvice's vestigial always-true boolean return and @Advice.Local
in favor of returning the AgentScope directly via @Advice.Enter, guarding the now-possible
null scope on close/cleanup.

Since the depth increment now happens before the Request-handled dedup check, mark the
Request as handled unconditionally on the nested path too, instead of skipping it — otherwise
a later async re-send of the same Request (e.g. via a pooled connection) could be mistaken
for a brand-new command and get double-spanned.

Guard the activeSpan() fallback used for connection decoration so it only tags a span that
is actually a REDIS_COMMAND span, rather than whatever happens to be active — this avoids
mistagging an unrelated span with Redis peer/connection info when the fallback resolves to
something other than the intended command span.

Adds a regression test asserting the call-depth counter is balanced after each test.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@mcculls
mcculls force-pushed the mcculls/cleanup-redis-advice branch from 44bfa56 to 9d3e164 Compare July 20, 2026 20:49
@mcculls
mcculls marked this pull request as ready for review July 20, 2026 20:50
@mcculls
mcculls requested a review from a team as a code owner July 20, 2026 20:50
@mcculls
mcculls requested review from vandonr and removed request for a team July 20, 2026 20:50
@dd-octo-sts dd-octo-sts Bot added the tag: ai generated Largely based on code generated by an AI or LLM label Jul 20, 2026
@mcculls
mcculls requested a review from amarziali July 20, 2026 20:50

@datadog-prod-us1-6 datadog-prod-us1-6 Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Datadog Autotest: PASS

More details

PR fixes a call-depth leak in Redis instrumentation by moving the call-depth increment to the first line of each advice method and making the corresponding decrement unconditional. The change prevents counter imbalance when early-returning on the "parent span already REDIS_COMMAND" branch. A new regression test asserts call-depth is balanced after each test, protecting against future leaks.

Was this helpful? React 👍 or 👎

📊 Validated against 5 scenarios · Open Bits AI session

🤖 Datadog Autotest · Commit 9d3e164 · What is Autotest? · Any feedback? Reach out in #autotest

@mcculls
mcculls requested a review from ygree July 21, 2026 07:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

inst: redis Redis instrumentation tag: ai generated Largely based on code generated by an AI or LLM tag: no release notes Changes to exclude from release notes type: refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants