diff --git a/instrumentation/lettuce/lettuce-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v4_0/LettuceAsyncCommandsInstrumentation.java b/instrumentation/lettuce/lettuce-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v4_0/LettuceAsyncCommandsInstrumentation.java index a16468a35cd5..37d9850d2a57 100644 --- a/instrumentation/lettuce/lettuce-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v4_0/LettuceAsyncCommandsInstrumentation.java +++ b/instrumentation/lettuce/lettuce-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v4_0/LettuceAsyncCommandsInstrumentation.java @@ -63,6 +63,10 @@ public void end( 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); // remember the context that called dispatch, it is used in LettuceAsyncCommandInstrumentation context = context.with(LettuceSingletons.COMMAND_CONTEXT_KEY, parentContext); @@ -72,10 +76,12 @@ public static AdviceScope onEnter(@Advice.Argument(0) RedisCommand comm @Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class) public static void onExit( @Advice.Argument(0) RedisCommand command, - @Advice.Thrown Throwable throwable, - @Advice.Return AsyncCommand asyncCommand, - @Advice.Enter AdviceScope adviceScope) { - adviceScope.end(throwable, command, asyncCommand); + @Advice.Thrown @Nullable Throwable throwable, + @Advice.Return @Nullable AsyncCommand asyncCommand, + @Advice.Enter @Nullable AdviceScope adviceScope) { + if (adviceScope != null) { + adviceScope.end(throwable, command, asyncCommand); + } } } } diff --git a/instrumentation/lettuce/lettuce-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v4_0/LettuceConnectInstrumentation.java b/instrumentation/lettuce/lettuce-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v4_0/LettuceConnectInstrumentation.java index aa1d094f946d..62851588ed98 100644 --- a/instrumentation/lettuce/lettuce-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v4_0/LettuceConnectInstrumentation.java +++ b/instrumentation/lettuce/lettuce-4.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v4_0/LettuceConnectInstrumentation.java @@ -54,7 +54,12 @@ public void end(Throwable throwable, RedisURI redisUri) { @Advice.OnMethodEnter(suppress = Throwable.class) public static AdviceScope onEnter(@Advice.Argument(1) RedisURI redisUri) { - Context context = connectInstrumenter().start(currentContext(), redisUri); + Context parentContext = currentContext(); + if (!connectInstrumenter().shouldStart(parentContext, redisUri)) { + return null; + } + + Context context = connectInstrumenter().start(parentContext, redisUri); return new AdviceScope(context, context.makeCurrent()); } @@ -62,8 +67,10 @@ public static AdviceScope onEnter(@Advice.Argument(1) RedisURI redisUri) { public static void onExit( @Advice.Argument(1) RedisURI redisUri, @Advice.Thrown @Nullable Throwable throwable, - @Advice.Enter AdviceScope adviceScope) { - adviceScope.end(throwable, redisUri); + @Advice.Enter @Nullable AdviceScope adviceScope) { + if (adviceScope != null) { + adviceScope.end(throwable, redisUri); + } } } } diff --git a/instrumentation/lettuce/lettuce-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/LettuceAsyncCommandsInstrumentation.java b/instrumentation/lettuce/lettuce-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/LettuceAsyncCommandsInstrumentation.java index 3b395f5f89ee..9c1f62655a4d 100644 --- a/instrumentation/lettuce/lettuce-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/LettuceAsyncCommandsInstrumentation.java +++ b/instrumentation/lettuce/lettuce-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/LettuceAsyncCommandsInstrumentation.java @@ -75,6 +75,10 @@ public void end( 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); // remember the context that called dispatch, it is used in LettuceAsyncCommandInstrumentation context = context.with(LettuceSingletons.COMMAND_CONTEXT_KEY, parentContext); @@ -85,10 +89,12 @@ public static AdviceScope onEnter(@Advice.Argument(0) RedisCommand comm public static void stopSpan( @Advice.Argument(0) RedisCommand command, @Advice.Thrown @Nullable Throwable throwable, - @Advice.Return AsyncCommand asyncCommand, - @Advice.Enter AdviceScope adviceScope) { + @Advice.Return @Nullable AsyncCommand asyncCommand, + @Advice.Enter @Nullable AdviceScope adviceScope) { - adviceScope.end(throwable, command, asyncCommand); + if (adviceScope != null) { + adviceScope.end(throwable, command, asyncCommand); + } } } } diff --git a/instrumentation/lettuce/lettuce-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/LettuceClientInstrumentation.java b/instrumentation/lettuce/lettuce-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/LettuceClientInstrumentation.java index c8d697023f22..54eabdc94212 100644 --- a/instrumentation/lettuce/lettuce-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/LettuceClientInstrumentation.java +++ b/instrumentation/lettuce/lettuce-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/LettuceClientInstrumentation.java @@ -72,7 +72,12 @@ public void end( @Advice.OnMethodEnter(suppress = Throwable.class) public static AdviceScope onEnter(@Advice.Argument(1) RedisURI redisUri) { - Context context = connectInstrumenter().start(currentContext(), redisUri); + Context parentContext = currentContext(); + if (!connectInstrumenter().shouldStart(parentContext, redisUri)) { + return null; + } + + Context context = connectInstrumenter().start(parentContext, redisUri); return new AdviceScope(context, context.makeCurrent()); } @@ -80,9 +85,11 @@ public static AdviceScope onEnter(@Advice.Argument(1) RedisURI redisUri) { public static void stopSpan( @Advice.Argument(1) RedisURI redisUri, @Advice.Thrown @Nullable Throwable throwable, - @Advice.Return ConnectionFuture connectionFuture, - @Advice.Enter AdviceScope adviceScope) { - adviceScope.end(throwable, redisUri, connectionFuture); + @Advice.Return @Nullable ConnectionFuture connectionFuture, + @Advice.Enter @Nullable AdviceScope adviceScope) { + if (adviceScope != null) { + adviceScope.end(throwable, redisUri, connectionFuture); + } } } }