Skip to content

Commit ab14103

Browse files
committed
lettuce-5.1
1 parent 0bcc258 commit ab14103

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

instrumentation/lettuce/lettuce-5.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_1/LettuceAsyncCommandInstrumentation.java

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55

66
package io.opentelemetry.javaagent.instrumentation.lettuce.v5_1;
77

8+
import static io.opentelemetry.javaagent.instrumentation.lettuce.v5_1.LettuceSingletons.CONTEXT;
89
import static net.bytebuddy.matcher.ElementMatchers.isConstructor;
910
import static net.bytebuddy.matcher.ElementMatchers.named;
1011
import static net.bytebuddy.matcher.ElementMatchers.namedOneOf;
1112

1213
import io.lettuce.core.protocol.AsyncCommand;
1314
import io.opentelemetry.context.Context;
1415
import io.opentelemetry.context.Scope;
15-
import io.opentelemetry.instrumentation.api.util.VirtualField;
1616
import io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge;
1717
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
1818
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
@@ -42,22 +42,21 @@ public static class SaveContextAdvice {
4242
@Advice.OnMethodExit(suppress = Throwable.class)
4343
public static void saveContext(@Advice.This AsyncCommand<?, ?, ?> asyncCommand) {
4444
Context context = Java8BytecodeBridge.currentContext();
45-
VirtualField.find(AsyncCommand.class, Context.class).set(asyncCommand, context);
45+
CONTEXT.set(asyncCommand, context);
4646
}
4747
}
4848

4949
@SuppressWarnings("unused")
5050
public static class RestoreContextAdvice {
5151

5252
@Advice.OnMethodEnter(suppress = Throwable.class)
53-
public static void onEnter(
54-
@Advice.This AsyncCommand<?, ?, ?> asyncCommand, @Advice.Local("otelScope") Scope scope) {
55-
Context context = VirtualField.find(AsyncCommand.class, Context.class).get(asyncCommand);
56-
scope = context.makeCurrent();
53+
public static Scope onEnter(@Advice.This AsyncCommand<?, ?, ?> asyncCommand) {
54+
Context context = CONTEXT.get(asyncCommand);
55+
return context.makeCurrent();
5756
}
5857

5958
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
60-
public static void onExit(@Advice.Local("otelScope") Scope scope) {
59+
public static void onExit(@Advice.Enter Scope scope) {
6160
scope.close();
6261
}
6362
}

instrumentation/lettuce/lettuce-5.1/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_1/LettuceInstrumentationModule.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@
1111
import com.google.auto.service.AutoService;
1212
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
1313
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
14+
import io.opentelemetry.javaagent.extension.instrumentation.internal.ExperimentalInstrumentationModule;
1415
import java.util.List;
1516
import net.bytebuddy.matcher.ElementMatcher;
1617

1718
@AutoService(InstrumentationModule.class)
18-
public class LettuceInstrumentationModule extends InstrumentationModule {
19+
public class LettuceInstrumentationModule extends InstrumentationModule
20+
implements ExperimentalInstrumentationModule {
1921

2022
public LettuceInstrumentationModule() {
2123
super("lettuce", "lettuce-5.1");
@@ -36,4 +38,9 @@ public List<TypeInstrumentation> typeInstrumentations() {
3638
return asList(
3739
new DefaultClientResourcesInstrumentation(), new LettuceAsyncCommandInstrumentation());
3840
}
41+
42+
@Override
43+
public boolean isIndyReady() {
44+
return true;
45+
}
3946
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.javaagent.instrumentation.lettuce.v5_1;
7+
8+
import io.lettuce.core.protocol.AsyncCommand;
9+
import io.opentelemetry.context.Context;
10+
import io.opentelemetry.instrumentation.api.util.VirtualField;
11+
12+
public class LettuceSingletons {
13+
14+
public static final VirtualField<AsyncCommand<?, ?, ?>, Context> CONTEXT =
15+
VirtualField.find(AsyncCommand.class, Context.class);
16+
17+
private LettuceSingletons() {}
18+
}

0 commit comments

Comments
 (0)