Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Sep 15, 2025

The lettuce javaagent instrumentations (versions 4.0 and 5.0) were creating spans even when instrumentation was disabled, bypassing the standard shouldStart pattern used by other OpenTelemetry instrumentations. This resulted in unnecessary span creation overhead and inconsistent behavior.

Problem

The lettuce javaagent instrumentations (versions 4.0 and 5.0) were directly creating spans without checking if instrumentation should be enabled:

Javaagent Instrumentation (lettuce-4.0, lettuce-5.0):

// Before: Always created spans regardless of instrumentation state
@Advice.OnMethodEnter(suppress = Throwable.class)
public static AdviceScope onEnter(@Advice.Argument(0) RedisCommand<?, ?, ?> command) {
  Context context = instrumenter().start(parentContext, command); // No shouldStart check
  return new AdviceScope(context, context.makeCurrent());
}

This meant spans would be created even when users wanted to disable lettuce instrumentation, leading to:

  • Unnecessary performance overhead
  • Inability to disable instrumentation programmatically
  • Inconsistency with other OpenTelemetry instrumentations

Solution

Added proper shouldStart checks using the standard Instrumenter pattern consistent with other OpenTelemetry instrumentations:

Javaagent Instrumentation (lettuce-4.0, lettuce-5.0):

// After: Check shouldStart before creating spans
@Advice.OnMethodEnter(suppress = Throwable.class)
public static AdviceScope onEnter(@Advice.Argument(0) RedisCommand<?, ?, ?> command) {
  Context parentContext = currentContext();
  if (!instrumenter().shouldStart(parentContext, command)) {
    return null;
  }
  Context context = instrumenter().start(parentContext, command);
  return new AdviceScope(context, context.makeCurrent());
}

Key Changes

Javaagent Instrumentation (lettuce-4.0, lettuce-5.0):

  1. Added shouldStart checks: Modified LettuceAsyncCommandsInstrumentation and connect instrumentation classes to check shouldStart before creating spans
  2. Null-safe exit handling: Added proper null checks in exit methods to handle disabled instrumentation
  3. Consistent pattern: Applied the same pattern used in JSP, Geode, and other javaagent instrumentations

Usage

Javaagent Usage (lettuce-4.0, lettuce-5.0):
The javaagent instrumentations now respect the standard OpenTelemetry instrumentation enablement configuration and will not create spans when instrumentation is disabled.

The implementation follows the same pattern used in other instrumentations like Ratpack, JSP, and Geode, ensuring consistency across the OpenTelemetry Java instrumentation ecosystem.

Fixes #14665.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Copy link
Contributor Author

Copilot AI commented Sep 15, 2025

@trask 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

Copilot AI changed the title [WIP] lettuce instrumentation check/fix span creation should be guarded by shouldStart Add shouldStart checks to lettuce instrumentation to prevent span creation when disabled Sep 15, 2025
Copilot AI requested a review from trask September 15, 2025 17:10
Copilot finished work on behalf of trask September 15, 2025 17:10
@trask
Copy link
Member

trask commented Sep 15, 2025

worth a try 🤷‍♂️

@trask trask closed this Sep 15, 2025
@trask trask reopened this Sep 15, 2025
@trask
Copy link
Member

trask commented Sep 15, 2025

@copilot this issue is about lettuce-4.0, not lettuce-5.1

Copy link
Contributor Author

Copilot AI commented Sep 15, 2025

@copilot this issue is about lettuce-4.0, not lettuce-5.1

You're absolutely right - the issue is about lettuce-4.0, not lettuce-5.1. I was working on the wrong version. I'm now focusing on fixing the shouldStart pattern in lettuce-4.0 (and lettuce-5.0 which has the same issue) javaagent instrumentation files. The lettuce-5.1 version uses library instrumentation which already follows the correct pattern.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • scans-in.gradle.com
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.xml/javax.xml.namespace=ALL-UNNAMED -XX:MaxMetaspaceSize=512m -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en -Duser.variant -cp /home/REDACTED/.gradle/wrapper/dists/gradle-9.0.0-bin/d6wjpkvcgsg3oed0qlfss3wgl/gradle-9.0.0/lib/gradle-daemon-main-9.0.0.jar -javaagent:/home/REDACTED/.gradle/wrapper/dists/gradle-9.0.0-bin/d6wjpkvcgsg3oed0qlfss3wgl/gradle-9.0.0/lib/agents/gradle-instrumentation-agent-9.0.0.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 9.0.0 (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of trask September 15, 2025 17:37
Copy link
Member

@trask trask left a comment

Choose a reason for hiding this comment

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

@copilot revert the changes to lettuce-5.1

Copy link
Contributor Author

Copilot AI commented Sep 15, 2025

@copilot revert the changes to lettuce-5.1

Done! I've reverted all lettuce-5.1 changes as requested (commit d95c3ac). The fix now focuses solely on lettuce-4.0 and lettuce-5.0 javaagent instrumentations, which is what the original issue #14665 was about.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • scans-in.gradle.com
    • Triggering command: /usr/lib/jvm/temurin-17-jdk-amd64/bin/java --add-opens=java.base/java.lang=ALL-UNNAMED --add-opens=java.base/java.lang.invoke=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED --add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED --add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.prefs/java.util.prefs=ALL-UNNAMED --add-opens=java.base/java.nio.charset=ALL-UNNAMED --add-opens=java.base/java.net=ALL-UNNAMED --add-opens=java.base/java.util.concurrent=ALL-UNNAMED --add-opens=java.base/java.util.concurrent.atomic=ALL-UNNAMED --add-opens=java.xml/javax.xml.namespace=ALL-UNNAMED -XX:MaxMetaspaceSize=512m -Dfile.encoding=UTF-8 -Duser.country -Duser.language=en -Duser.variant -cp /home/REDACTED/.gradle/wrapper/dists/gradle-9.0.0-bin/d6wjpkvcgsg3oed0qlfss3wgl/gradle-9.0.0/lib/gradle-daemon-main-9.0.0.jar -javaagent:/home/REDACTED/.gradle/wrapper/dists/gradle-9.0.0-bin/d6wjpkvcgsg3oed0qlfss3wgl/gradle-9.0.0/lib/agents/gradle-instrumentation-agent-9.0.0.jar org.gradle.launcher.daemon.bootstrap.GradleDaemon 9.0.0 (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title Add shouldStart checks to lettuce instrumentation to prevent span creation when disabled Add shouldStart checks to lettuce-4.0 and lettuce-5.0 javaagent instrumentation to prevent span creation when disabled Sep 15, 2025
Copilot AI requested a review from trask September 15, 2025 17:49
Copilot finished work on behalf of trask September 15, 2025 17:49
Copy link
Contributor

@SylvainJuge SylvainJuge left a comment

Choose a reason for hiding this comment

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

LGTM, just a few minor suggestions to add @Nullable where relevant in the modified code.

@trask trask marked this pull request as ready for review September 17, 2025 14:10
@trask trask requested a review from a team as a code owner September 17, 2025 14:10
@otelbot-java-instrumentation
Copy link
Contributor

🔧 The result from spotlessApply was committed to the PR branch.

@trask trask merged commit 3326a59 into main Sep 17, 2025
90 checks passed
@trask trask deleted the copilot/fix-14665 branch September 17, 2025 15:13
mznet pushed a commit to mznet/opentelemetry-java-instrumentation that referenced this pull request Sep 26, 2025
…umentation to prevent span creation when disabled (open-telemetry#14666)

Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: trask <[email protected]>
Co-authored-by: Trask Stalnaker <[email protected]>
Co-authored-by: SylvainJuge <[email protected]>
Co-authored-by: otelbot <[email protected]>
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.

lettuce instrumentation check/fix span creation should be guarded by shouldStart

3 participants