|
5 | 5 |
|
6 | 6 | package io.opentelemetry.javaagent.instrumentation.lettuce.v5_1; |
7 | 7 |
|
| 8 | +import static io.opentelemetry.javaagent.instrumentation.lettuce.v5_1.LettuceSingletons.CONTEXT; |
8 | 9 | import static net.bytebuddy.matcher.ElementMatchers.isConstructor; |
9 | 10 | import static net.bytebuddy.matcher.ElementMatchers.named; |
10 | 11 | import static net.bytebuddy.matcher.ElementMatchers.namedOneOf; |
11 | 12 |
|
12 | 13 | import io.lettuce.core.protocol.AsyncCommand; |
13 | 14 | import io.opentelemetry.context.Context; |
14 | 15 | import io.opentelemetry.context.Scope; |
15 | | -import io.opentelemetry.instrumentation.api.util.VirtualField; |
16 | 16 | import io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge; |
17 | 17 | import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; |
18 | 18 | import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; |
@@ -42,22 +42,21 @@ public static class SaveContextAdvice { |
42 | 42 | @Advice.OnMethodExit(suppress = Throwable.class) |
43 | 43 | public static void saveContext(@Advice.This AsyncCommand<?, ?, ?> asyncCommand) { |
44 | 44 | Context context = Java8BytecodeBridge.currentContext(); |
45 | | - VirtualField.find(AsyncCommand.class, Context.class).set(asyncCommand, context); |
| 45 | + CONTEXT.set(asyncCommand, context); |
46 | 46 | } |
47 | 47 | } |
48 | 48 |
|
49 | 49 | @SuppressWarnings("unused") |
50 | 50 | public static class RestoreContextAdvice { |
51 | 51 |
|
52 | 52 | @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(); |
57 | 56 | } |
58 | 57 |
|
59 | 58 | @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) { |
61 | 60 | scope.close(); |
62 | 61 | } |
63 | 62 | } |
|
0 commit comments