Skip to content

Commit 6159891

Browse files
Copilottrask
andcommitted
Fix shouldStart pattern in lettuce-4.0 and lettuce-5.0 javaagent instrumentations
Co-authored-by: trask <[email protected]>
1 parent 60ac4bf commit 6159891

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

instrumentation/lettuce/lettuce-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v4_0/LettuceAsyncCommandsInstrumentation.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ public void end(
6363
public static AdviceScope onEnter(@Advice.Argument(0) RedisCommand<?, ?, ?> command) {
6464

6565
Context parentContext = currentContext();
66+
if (!instrumenter().shouldStart(parentContext, command)) {
67+
return null;
68+
}
69+
6670
Context context = instrumenter().start(parentContext, command);
6771
// remember the context that called dispatch, it is used in LettuceAsyncCommandInstrumentation
6872
context = context.with(LettuceSingletons.COMMAND_CONTEXT_KEY, parentContext);
@@ -75,7 +79,9 @@ public static void onExit(
7579
@Advice.Thrown Throwable throwable,
7680
@Advice.Return AsyncCommand<?, ?, ?> asyncCommand,
7781
@Advice.Enter AdviceScope adviceScope) {
78-
adviceScope.end(throwable, command, asyncCommand);
82+
if (adviceScope != null) {
83+
adviceScope.end(throwable, command, asyncCommand);
84+
}
7985
}
8086
}
8187
}

instrumentation/lettuce/lettuce-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v4_0/LettuceConnectInstrumentation.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,12 @@ public void end(Throwable throwable, RedisURI redisUri) {
5454

5555
@Advice.OnMethodEnter(suppress = Throwable.class)
5656
public static AdviceScope onEnter(@Advice.Argument(1) RedisURI redisUri) {
57-
Context context = connectInstrumenter().start(currentContext(), redisUri);
57+
Context parentContext = currentContext();
58+
if (!connectInstrumenter().shouldStart(parentContext, redisUri)) {
59+
return null;
60+
}
61+
62+
Context context = connectInstrumenter().start(parentContext, redisUri);
5863
return new AdviceScope(context, context.makeCurrent());
5964
}
6065

@@ -63,7 +68,9 @@ public static void onExit(
6368
@Advice.Argument(1) RedisURI redisUri,
6469
@Advice.Thrown @Nullable Throwable throwable,
6570
@Advice.Enter AdviceScope adviceScope) {
66-
adviceScope.end(throwable, redisUri);
71+
if (adviceScope != null) {
72+
adviceScope.end(throwable, redisUri);
73+
}
6774
}
6875
}
6976
}

instrumentation/lettuce/lettuce-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/LettuceAsyncCommandsInstrumentation.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,10 @@ public void end(
7575
public static AdviceScope onEnter(@Advice.Argument(0) RedisCommand<?, ?, ?> command) {
7676

7777
Context parentContext = currentContext();
78+
if (!instrumenter().shouldStart(parentContext, command)) {
79+
return null;
80+
}
81+
7882
Context context = instrumenter().start(parentContext, command);
7983
// remember the context that called dispatch, it is used in LettuceAsyncCommandInstrumentation
8084
context = context.with(LettuceSingletons.COMMAND_CONTEXT_KEY, parentContext);
@@ -88,7 +92,9 @@ public static void stopSpan(
8892
@Advice.Return AsyncCommand<?, ?, ?> asyncCommand,
8993
@Advice.Enter AdviceScope adviceScope) {
9094

91-
adviceScope.end(throwable, command, asyncCommand);
95+
if (adviceScope != null) {
96+
adviceScope.end(throwable, command, asyncCommand);
97+
}
9298
}
9399
}
94100
}

instrumentation/lettuce/lettuce-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/LettuceClientInstrumentation.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,12 @@ public void end(
7272

7373
@Advice.OnMethodEnter(suppress = Throwable.class)
7474
public static AdviceScope onEnter(@Advice.Argument(1) RedisURI redisUri) {
75-
Context context = connectInstrumenter().start(currentContext(), redisUri);
75+
Context parentContext = currentContext();
76+
if (!connectInstrumenter().shouldStart(parentContext, redisUri)) {
77+
return null;
78+
}
79+
80+
Context context = connectInstrumenter().start(parentContext, redisUri);
7681
return new AdviceScope(context, context.makeCurrent());
7782
}
7883

@@ -82,7 +87,9 @@ public static void stopSpan(
8287
@Advice.Thrown @Nullable Throwable throwable,
8388
@Advice.Return ConnectionFuture<?> connectionFuture,
8489
@Advice.Enter AdviceScope adviceScope) {
85-
adviceScope.end(throwable, redisUri, connectionFuture);
90+
if (adviceScope != null) {
91+
adviceScope.end(throwable, redisUri, connectionFuture);
92+
}
8693
}
8794
}
8895
}

0 commit comments

Comments
 (0)