Skip to content

Commit 2466290

Browse files
committed
fix few other virtualfield mis-usages
1 parent f01093a commit 2466290

File tree

5 files changed

+20
-11
lines changed

5 files changed

+20
-11
lines changed

instrumentation/async-http-client/async-http-client-1.9/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/asynchttpclient/v1_9/AsyncHttpClientSingletons.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public static Instrumenter<Request, Response> instrumenter() {
3333
return INSTRUMENTER;
3434
}
3535

36-
public static VirtualField<AsyncHandler<?>, AsyncHandlerData> getVirtualField() {
36+
public static VirtualField<AsyncHandler<?>, AsyncHandlerData> virtualField() {
3737
return VIRTUAL_FIELD;
3838
}
3939

instrumentation/async-http-client/async-http-client-1.9/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/asynchttpclient/v1_9/RequestInstrumentation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
package io.opentelemetry.javaagent.instrumentation.asynchttpclient.v1_9;
77

88
import static io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge.currentContext;
9-
import static io.opentelemetry.javaagent.instrumentation.asynchttpclient.v1_9.AsyncHttpClientSingletons.getVirtualField;
109
import static io.opentelemetry.javaagent.instrumentation.asynchttpclient.v1_9.AsyncHttpClientSingletons.instrumenter;
10+
import static io.opentelemetry.javaagent.instrumentation.asynchttpclient.v1_9.AsyncHttpClientSingletons.virtualField;
1111
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
1212
import static net.bytebuddy.matcher.ElementMatchers.named;
1313
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
@@ -53,7 +53,7 @@ public static Scope onEnter(
5353
}
5454

5555
Context context = instrumenter().start(parentContext, request);
56-
getVirtualField().set(handler, AsyncHandlerData.create(parentContext, context, request));
56+
virtualField().set(handler, AsyncHandlerData.create(parentContext, context, request));
5757
return context.makeCurrent();
5858
}
5959

instrumentation/async-http-client/async-http-client-1.9/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/asynchttpclient/v1_9/ResponseInstrumentation.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
package io.opentelemetry.javaagent.instrumentation.asynchttpclient.v1_9;
77

88
import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed;
9-
import static io.opentelemetry.javaagent.instrumentation.asynchttpclient.v1_9.AsyncHttpClientSingletons.getVirtualField;
109
import static io.opentelemetry.javaagent.instrumentation.asynchttpclient.v1_9.AsyncHttpClientSingletons.instrumenter;
10+
import static io.opentelemetry.javaagent.instrumentation.asynchttpclient.v1_9.AsyncHttpClientSingletons.virtualField;
1111
import static net.bytebuddy.matcher.ElementMatchers.hasSuperClass;
1212
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
1313
import static net.bytebuddy.matcher.ElementMatchers.named;
@@ -55,12 +55,12 @@ public static class OnCompletedAdvice {
5555
public static Scope onEnter(
5656
@Advice.This AsyncCompletionHandler<?> handler, @Advice.Argument(0) Response response) {
5757

58-
VirtualField<AsyncHandler<?>, AsyncHandlerData> virtualField = getVirtualField();
59-
AsyncHandlerData data = getVirtualField().get(handler);
58+
VirtualField<AsyncHandler<?>, AsyncHandlerData> virtualField = virtualField();
59+
AsyncHandlerData data = virtualField().get(handler);
6060
if (data == null) {
6161
return null;
6262
}
63-
getVirtualField().set(handler, null);
63+
virtualField().set(handler, null);
6464
instrumenter().end(data.getContext(), data.getRequest(), response, null);
6565
return data.getParentContext().makeCurrent();
6666
}
@@ -80,11 +80,11 @@ public static class OnThrowableAdvice {
8080
public static Scope onEnter(
8181
@Advice.This AsyncCompletionHandler<?> handler, @Advice.Argument(0) Throwable throwable) {
8282

83-
AsyncHandlerData data = getVirtualField().get(handler);
83+
AsyncHandlerData data = virtualField().get(handler);
8484
if (data == null) {
8585
return null;
8686
}
87-
getVirtualField().set(handler, null);
87+
virtualField().set(handler, null);
8888
instrumenter().end(data.getContext(), data.getRequest(), null, throwable);
8989
return data.getParentContext().makeCurrent();
9090
}

instrumentation/async-http-client/async-http-client-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/asynchttpclient/v2_0/AsyncHttpClientInstrumentation.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
import static io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge.currentContext;
99
import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.implementsInterface;
1010
import static io.opentelemetry.javaagent.instrumentation.asynchttpclient.v2_0.AsyncHttpClientSingletons.instrumenter;
11+
import static io.opentelemetry.javaagent.instrumentation.asynchttpclient.v2_0.AsyncHttpClientSingletons.virtualField;
1112
import static net.bytebuddy.matcher.ElementMatchers.isPublic;
1213
import static net.bytebuddy.matcher.ElementMatchers.named;
1314
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;
1415

1516
import io.opentelemetry.context.Context;
1617
import io.opentelemetry.context.Scope;
17-
import io.opentelemetry.instrumentation.api.util.VirtualField;
1818
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
1919
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
2020
import javax.annotation.Nullable;
@@ -71,7 +71,7 @@ public static Scope onEnter(
7171
// 2.1, so the instrumentation module will need to be essentially duplicated (or a common
7272
// module introduced)
7373

74-
VirtualField.find(AsyncHandler.class, RequestContext.class).set(handler, requestContext);
74+
virtualField().set(handler, requestContext);
7575
return context.makeCurrent();
7676
}
7777

instrumentation/async-http-client/async-http-client-2.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/asynchttpclient/v2_0/AsyncHttpClientSingletons.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,34 @@
66
package io.opentelemetry.javaagent.instrumentation.asynchttpclient.v2_0;
77

88
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
9+
import io.opentelemetry.instrumentation.api.util.VirtualField;
910
import io.opentelemetry.javaagent.bootstrap.internal.JavaagentHttpClientInstrumenters;
11+
import org.asynchttpclient.AsyncHandler;
1012
import org.asynchttpclient.Response;
1113

1214
public final class AsyncHttpClientSingletons {
1315
private static final String INSTRUMENTATION_NAME = "io.opentelemetry.async-http-client-2.0";
1416

1517
private static final Instrumenter<RequestContext, Response> INSTRUMENTER;
18+
private static final VirtualField<AsyncHandler<?>, RequestContext> VIRTUAL_FIELD;
1619

1720
static {
1821
INSTRUMENTER =
1922
JavaagentHttpClientInstrumenters.create(
2023
INSTRUMENTATION_NAME,
2124
new AsyncHttpClientHttpAttributesGetter(),
2225
HttpHeaderSetter.INSTANCE);
26+
27+
VIRTUAL_FIELD = VirtualField.find(AsyncHandler.class, RequestContext.class);
2328
}
2429

2530
public static Instrumenter<RequestContext, Response> instrumenter() {
2631
return INSTRUMENTER;
2732
}
2833

34+
public static VirtualField<AsyncHandler<?>, RequestContext> virtualField() {
35+
return VIRTUAL_FIELD;
36+
}
37+
2938
private AsyncHttpClientSingletons() {}
3039
}

0 commit comments

Comments
 (0)