Skip to content

Commit 8f574db

Browse files
committed
simplify
1 parent b6595af commit 8f574db

File tree

4 files changed

+19
-80
lines changed

4 files changed

+19
-80
lines changed

instrumentation/vertx/vertx-http-client/vertx-http-client-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vertx/v5_0/client/HttpClientImplInstrumentation.java

Lines changed: 0 additions & 41 deletions
This file was deleted.

instrumentation/vertx/vertx-http-client/vertx-http-client-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vertx/v5_0/client/ResourceManagerInstrumentation.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
1212
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
1313
import io.vertx.core.Future;
14-
import io.vertx.core.internal.VertxInternal;
15-
import io.vertx.core.internal.resource.ResourceManager;
1614
import net.bytebuddy.asm.Advice;
1715
import net.bytebuddy.description.type.TypeDescription;
1816
import net.bytebuddy.matcher.ElementMatcher;
@@ -35,13 +33,8 @@ public void transform(TypeTransformer transformer) {
3533
@SuppressWarnings("unused")
3634
public static class WithResourceAsyncAdvice {
3735
@Advice.OnMethodExit(suppress = Throwable.class)
38-
public static void wrapFuture(
39-
@Advice.This ResourceManager<?, ?> resourceManager,
40-
@Advice.Return(readOnly = false) Future<?> future) {
41-
VertxInternal vertx = VertxClientSingletons.getVertx(resourceManager);
42-
if (vertx != null) {
43-
future = VertxClientSingletons.wrapFuture(vertx.getOrCreateContext(), future);
44-
}
36+
public static void wrapFuture(@Advice.Return(readOnly = false) Future<?> future) {
37+
future = VertxClientSingletons.wrapFuture(future);
4538
}
4639
}
4740
}

instrumentation/vertx/vertx-http-client/vertx-http-client-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vertx/v5_0/client/VertxClientInstrumentationModule.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ public List<TypeInstrumentation> typeInstrumentations() {
3232
return asList(
3333
new HttpRequestInstrumentation(),
3434
new HttpClientRequestBaseInstrumentation(),
35-
new ResourceManagerInstrumentation(),
36-
new HttpClientImplInstrumentation());
35+
new ResourceManagerInstrumentation());
3736
}
3837
}

instrumentation/vertx/vertx-http-client/vertx-http-client-5.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/vertx/v5_0/client/VertxClientSingletons.java

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,10 @@
1111
import io.opentelemetry.instrumentation.api.util.VirtualField;
1212
import io.opentelemetry.javaagent.instrumentation.vertx.client.VertxClientInstrumenterFactory;
1313
import io.vertx.core.Future;
14-
import io.vertx.core.Promise;
1514
import io.vertx.core.http.HttpClientRequest;
1615
import io.vertx.core.http.HttpClientResponse;
17-
import io.vertx.core.internal.ContextInternal;
18-
import io.vertx.core.internal.VertxInternal;
19-
import io.vertx.core.internal.resource.ResourceManager;
2016
import io.vertx.core.net.HostAndPort;
17+
import java.util.concurrent.CompletableFuture;
2118

2219
public final class VertxClientSingletons {
2320

@@ -40,31 +37,22 @@ public static HostAndPort getAuthority(HttpClientRequest request) {
4037
return authorityField.get(request);
4138
}
4239

43-
private static final VirtualField<ResourceManager<?, ?>, VertxInternal> vertxField =
44-
VirtualField.find(ResourceManager.class, VertxInternal.class);
45-
46-
public static void setVertx(ResourceManager<?, ?> resourceManager, VertxInternal vertx) {
47-
vertxField.set(resourceManager, vertx);
48-
}
49-
50-
public static VertxInternal getVertx(ResourceManager<?, ?> resourceManager) {
51-
return vertxField.get(resourceManager);
52-
}
53-
54-
public static <T> Future<T> wrapFuture(ContextInternal vertxContext, Future<T> future) {
40+
public static <T> Future<T> wrapFuture(Future<T> future) {
5541
Context context = Context.current();
56-
Promise<T> promise = vertxContext.promise();
57-
future.onComplete(
58-
result -> {
59-
try (Scope ignore = context.makeCurrent()) {
60-
if (result.failed()) {
61-
promise.fail(result.cause());
62-
} else {
63-
promise.complete(result.result());
64-
}
65-
}
66-
});
67-
return promise.future();
42+
CompletableFuture<T> result = new CompletableFuture<>();
43+
future
44+
.toCompletionStage()
45+
.whenComplete(
46+
(value, throwable) -> {
47+
try (Scope ignore = context.makeCurrent()) {
48+
if (throwable != null) {
49+
result.completeExceptionally(throwable);
50+
} else {
51+
result.complete(value);
52+
}
53+
}
54+
});
55+
return Future.fromCompletionStage(result);
6856
}
6957

7058
private VertxClientSingletons() {}

0 commit comments

Comments
 (0)