Skip to content

Commit efa5469

Browse files
authored
Review fixes for async-http-client-2.0:javaagent (open-telemetry#17266)
Co-authored-by: otelbot <197425009+otelbot@users.noreply.github.com>
1 parent 76e005c commit efa5469

3 files changed

Lines changed: 11 additions & 6 deletions

File tree

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import io.opentelemetry.context.Scope;
1717
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
1818
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
19+
import javax.annotation.Nullable;
1920
import net.bytebuddy.asm.Advice;
2021
import net.bytebuddy.description.type.TypeDescription;
2122
import net.bytebuddy.matcher.ElementMatcher;
@@ -49,6 +50,7 @@ public void transform(TypeTransformer transformer) {
4950
@SuppressWarnings("unused")
5051
public static class OnCompletedAdvice {
5152

53+
@Nullable
5254
@Advice.OnMethodEnter(suppress = Throwable.class)
5355
public static Scope onEnter(
5456
@Advice.This AsyncCompletionHandler<?> handler, @Advice.Argument(0) Response response) {
@@ -63,7 +65,7 @@ public static Scope onEnter(
6365
}
6466

6567
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
66-
public static void onExit(@Advice.Enter Scope scope) {
68+
public static void onExit(@Advice.Enter @Nullable Scope scope) {
6769
if (null != scope) {
6870
scope.close();
6971
}
@@ -73,6 +75,7 @@ public static void onExit(@Advice.Enter Scope scope) {
7375
@SuppressWarnings("unused")
7476
public static class OnThrowableAdvice {
7577

78+
@Nullable
7679
@Advice.OnMethodEnter(suppress = Throwable.class)
7780
public static Scope onEnter(
7881
@Advice.This AsyncCompletionHandler<?> handler, @Advice.Argument(0) Throwable throwable) {
@@ -87,7 +90,7 @@ public static Scope onEnter(
8790
}
8891

8992
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
90-
public static void onExit(@Advice.Enter Scope scope) {
93+
public static void onExit(@Advice.Enter @Nullable Scope scope) {
9194
if (null != scope) {
9295
scope.close();
9396
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
public final class AsyncHttpClientSingletons {
1717
private static final String INSTRUMENTATION_NAME = "io.opentelemetry.async-http-client-2.0";
1818

19-
private static final Instrumenter<RequestContext, Response> INSTRUMENTER;
19+
private static final Instrumenter<RequestContext, Response> instrumenter;
2020
public static final VirtualField<AsyncHandler<?>, RequestContext> ASYNC_HANDLER_REQUEST_CONTEXT;
2121
public static final VirtualField<Request, Context> REQUEST_CONTEXT;
2222

2323
static {
24-
INSTRUMENTER =
24+
instrumenter =
2525
JavaagentHttpClientInstrumenters.create(
2626
INSTRUMENTATION_NAME,
2727
new AsyncHttpClientHttpAttributesGetter(),
@@ -32,7 +32,7 @@ public final class AsyncHttpClientSingletons {
3232
}
3333

3434
public static Instrumenter<RequestContext, Response> instrumenter() {
35-
return INSTRUMENTER;
35+
return instrumenter;
3636
}
3737

3838
private AsyncHttpClientSingletons() {}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import io.opentelemetry.javaagent.bootstrap.Java8BytecodeBridge;
1818
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
1919
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
20+
import javax.annotation.Nullable;
2021
import net.bytebuddy.asm.Advice;
2122
import net.bytebuddy.description.type.TypeDescription;
2223
import net.bytebuddy.matcher.ElementMatcher;
@@ -66,6 +67,7 @@ public static void attachContext(@Advice.Argument(0) Request request) {
6667
@SuppressWarnings("unused")
6768
public static class MountContextAdvice {
6869

70+
@Nullable
6971
@Advice.OnMethodEnter(suppress = Throwable.class)
7072
public static Scope mountContext(@Advice.Argument(0) NettyResponseFuture<?> responseFuture) {
7173
Request request = responseFuture.getCurrentRequest();
@@ -74,7 +76,7 @@ public static Scope mountContext(@Advice.Argument(0) NettyResponseFuture<?> resp
7476
}
7577

7678
@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
77-
public static void unmountContext(@Advice.Enter Scope scope) {
79+
public static void unmountContext(@Advice.Enter @Nullable Scope scope) {
7880
if (scope != null) {
7981
scope.close();
8082
}

0 commit comments

Comments
 (0)