-
Notifications
You must be signed in to change notification settings - Fork 909
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Vertx http client 4 instrumentation (#3665)
* Vertx http client 4 instrumentation * remove debugging * rebase
- Loading branch information
Showing
21 changed files
with
686 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
.../java/io/opentelemetry/javaagent/instrumentation/vertx/v3_0/client/VertxClientTracer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.vertx.v3_0.client; | ||
|
||
import io.opentelemetry.javaagent.instrumentation.vertx.client.AbstractVertxClientTracer; | ||
import io.vertx.core.http.HttpClientRequest; | ||
import java.net.URI; | ||
import java.net.URISyntaxException; | ||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
||
public class VertxClientTracer extends AbstractVertxClientTracer { | ||
private static final VertxClientTracer TRACER = new VertxClientTracer(); | ||
|
||
public static VertxClientTracer tracer() { | ||
return TRACER; | ||
} | ||
|
||
@Override | ||
protected String getInstrumentationName() { | ||
return "io.opentelemetry.vertx-http-client-3.0"; | ||
} | ||
|
||
@Override | ||
protected String method(HttpClientRequest request) { | ||
return request.method().name(); | ||
} | ||
|
||
@Override | ||
@Nullable | ||
protected URI url(HttpClientRequest request) throws URISyntaxException { | ||
return new URI(request.uri()); | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
20 changes: 20 additions & 0 deletions
20
instrumentation/vertx-http-client/vertx-http-client-4.0/javaagent/build.gradle.kts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
plugins { | ||
id("otel.javaagent-instrumentation") | ||
} | ||
|
||
muzzle { | ||
pass { | ||
group.set("io.vertx") | ||
module.set("vertx-core") | ||
versions.set("[4.0.0,)") | ||
assertInverse.set(true) | ||
} | ||
} | ||
|
||
dependencies { | ||
library("io.vertx:vertx-core:4.0.0") | ||
|
||
implementation(project(":instrumentation:vertx-http-client:vertx-http-client-common:javaagent")) | ||
|
||
testInstrumentation(project(":instrumentation:netty:netty-4.1:javaagent")) | ||
} |
54 changes: 54 additions & 0 deletions
54
...lemetry/javaagent/instrumentation/vertx/v4_0/client/ConnectionManagerInstrumentation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.vertx.v4_0.client; | ||
|
||
import static net.bytebuddy.matcher.ElementMatchers.named; | ||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument; | ||
|
||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; | ||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; | ||
import io.vertx.core.Handler; | ||
import net.bytebuddy.asm.Advice; | ||
import net.bytebuddy.description.type.TypeDescription; | ||
import net.bytebuddy.matcher.ElementMatcher; | ||
|
||
/** Propagate context to connection established callback. */ | ||
public class ConnectionManagerInstrumentation implements TypeInstrumentation { | ||
|
||
@Override | ||
public ElementMatcher<TypeDescription> typeMatcher() { | ||
return named("io.vertx.core.net.impl.clientconnection.ConnectionManager") // 4.0.0 | ||
.or(named("io.vertx.core.net.impl.pool.ConnectionManager")); // 4.1.0 | ||
} | ||
|
||
@Override | ||
public void transform(TypeTransformer transformer) { | ||
transformer.applyAdviceToMethod( | ||
named("getConnection").and(takesArgument(2, named("io.vertx.core.Handler"))), | ||
ConnectionManagerInstrumentation.class.getName() + "$GetConnectionArg2Advice"); | ||
transformer.applyAdviceToMethod( | ||
named("getConnection").and(takesArgument(3, named("io.vertx.core.Handler"))), | ||
ConnectionManagerInstrumentation.class.getName() + "$GetConnectionArg3Advice"); | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
public static class GetConnectionArg2Advice { | ||
@Advice.OnMethodEnter(suppress = Throwable.class) | ||
public static void wrapHandler( | ||
@Advice.Argument(value = 2, readOnly = false) Handler<?> handler) { | ||
handler = HandlerWrapper.wrap(handler); | ||
} | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
public static class GetConnectionArg3Advice { | ||
@Advice.OnMethodEnter(suppress = Throwable.class) | ||
public static void wrapHandler( | ||
@Advice.Argument(value = 3, readOnly = false) Handler<?> handler) { | ||
handler = HandlerWrapper.wrap(handler); | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...ain/java/io/opentelemetry/javaagent/instrumentation/vertx/v4_0/client/HandlerWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.vertx.v4_0.client; | ||
|
||
import io.opentelemetry.context.Context; | ||
import io.opentelemetry.context.Scope; | ||
import io.vertx.core.Handler; | ||
|
||
public class HandlerWrapper<T> implements Handler<T> { | ||
private final Handler<T> delegate; | ||
private final Context context; | ||
|
||
private HandlerWrapper(Handler<T> delegate, Context context) { | ||
this.delegate = delegate; | ||
this.context = context; | ||
} | ||
|
||
public static <T> Handler<T> wrap(Handler<T> handler) { | ||
Context current = Context.current(); | ||
if (handler != null && !(handler instanceof HandlerWrapper) && current != Context.root()) { | ||
handler = new HandlerWrapper<>(handler, current); | ||
} | ||
return handler; | ||
} | ||
|
||
@Override | ||
public void handle(T t) { | ||
try (Scope ignore = context.makeCurrent()) { | ||
delegate.handle(t); | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...etry/javaagent/instrumentation/vertx/v4_0/client/HttpClientConnectionInstrumentation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.vertx.v4_0.client; | ||
|
||
import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.hasClassesNamed; | ||
import static io.opentelemetry.javaagent.extension.matcher.AgentElementMatchers.implementsInterface; | ||
import static net.bytebuddy.matcher.ElementMatchers.named; | ||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument; | ||
|
||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; | ||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; | ||
import io.vertx.core.Handler; | ||
import net.bytebuddy.asm.Advice; | ||
import net.bytebuddy.description.type.TypeDescription; | ||
import net.bytebuddy.matcher.ElementMatcher; | ||
|
||
/** Propagate context to stream opened callback. */ | ||
public class HttpClientConnectionInstrumentation implements TypeInstrumentation { | ||
|
||
@Override | ||
public ElementMatcher<TypeDescription> typeMatcher() { | ||
return implementsInterface(named("io.vertx.core.http.impl.HttpClientConnection")); | ||
} | ||
|
||
@Override | ||
public ElementMatcher<ClassLoader> classLoaderOptimization() { | ||
return hasClassesNamed("io.vertx.core.http.impl.HttpClientConnection"); | ||
} | ||
|
||
@Override | ||
public void transform(TypeTransformer transformer) { | ||
transformer.applyAdviceToMethod( | ||
named("createStream").and(takesArgument(1, named("io.vertx.core.Handler"))), | ||
HttpClientConnectionInstrumentation.class.getName() + "$CreateStreamAdvice"); | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
public static class CreateStreamAdvice { | ||
@Advice.OnMethodEnter(suppress = Throwable.class) | ||
public static void wrapHandler( | ||
@Advice.Argument(value = 1, readOnly = false) Handler<?> handler) { | ||
handler = HandlerWrapper.wrap(handler); | ||
} | ||
} | ||
} |
Oops, something went wrong.