-
Notifications
You must be signed in to change notification settings - Fork 813
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix http.url handing in vert.x 3 http client (#4739)
* Fix http.url handing in vert.x 3 http client * correct version * fix build * if https test is disabled use http for non routable aadress test * if https test is disabled use http for non routable aadress test * use StringBuilder
- Loading branch information
Showing
13 changed files
with
204 additions
and
15 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
41 changes: 41 additions & 0 deletions
41
...ntelemetry/javaagent/instrumentation/vertx/v3_0/client/HttpClientImplInstrumentation.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,41 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.vertx.v3_0.client; | ||
|
||
import static net.bytebuddy.matcher.ElementMatchers.isConstructor; | ||
import static net.bytebuddy.matcher.ElementMatchers.named; | ||
|
||
import io.opentelemetry.instrumentation.api.field.VirtualField; | ||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; | ||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; | ||
import io.vertx.core.http.HttpClientOptions; | ||
import io.vertx.core.http.impl.HttpClientImpl; | ||
import net.bytebuddy.asm.Advice; | ||
import net.bytebuddy.description.type.TypeDescription; | ||
import net.bytebuddy.matcher.ElementMatcher; | ||
|
||
public class HttpClientImplInstrumentation implements TypeInstrumentation { | ||
|
||
@Override | ||
public ElementMatcher<TypeDescription> typeMatcher() { | ||
return named("io.vertx.core.http.impl.HttpClientImpl"); | ||
} | ||
|
||
@Override | ||
public void transform(TypeTransformer transformer) { | ||
transformer.applyAdviceToMethod( | ||
isConstructor(), HttpClientImplInstrumentation.class.getName() + "$AttachStateAdvice"); | ||
} | ||
|
||
public static class AttachStateAdvice { | ||
@Advice.OnMethodExit(suppress = Throwable.class) | ||
public static void attachHttpClientOptions( | ||
@Advice.This HttpClientImpl client, | ||
@Advice.FieldValue("options") HttpClientOptions options) { | ||
VirtualField.find(HttpClientImpl.class, HttpClientOptions.class).set(client, options); | ||
} | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
...telemetry/javaagent/instrumentation/vertx/v3_0/client/HttpRequestImplInstrumentation.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,88 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.vertx.v3_0.client; | ||
|
||
import static net.bytebuddy.matcher.ElementMatchers.isConstructor; | ||
import static net.bytebuddy.matcher.ElementMatchers.named; | ||
import static net.bytebuddy.matcher.ElementMatchers.takesArgument; | ||
|
||
import io.opentelemetry.instrumentation.api.field.VirtualField; | ||
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation; | ||
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer; | ||
import io.vertx.core.http.HttpClientOptions; | ||
import io.vertx.core.http.HttpClientRequest; | ||
import io.vertx.core.http.impl.HttpClientImpl; | ||
import net.bytebuddy.asm.Advice; | ||
import net.bytebuddy.description.type.TypeDescription; | ||
import net.bytebuddy.matcher.ElementMatcher; | ||
|
||
public class HttpRequestImplInstrumentation implements TypeInstrumentation { | ||
|
||
@Override | ||
public ElementMatcher<TypeDescription> typeMatcher() { | ||
return named("io.vertx.core.http.impl.HttpClientRequestImpl"); | ||
} | ||
|
||
@Override | ||
public void transform(TypeTransformer transformer) { | ||
transformer.applyAdviceToMethod( | ||
isConstructor().and(takesArgument(2, String.class)).and(takesArgument(3, int.class)), | ||
HttpRequestImplInstrumentation.class.getName() + "$Vertx30Advice"); | ||
transformer.applyAdviceToMethod( | ||
isConstructor() | ||
.and(takesArgument(1, boolean.class)) | ||
.and(takesArgument(3, String.class)) | ||
.and(takesArgument(4, int.class)), | ||
HttpRequestImplInstrumentation.class.getName() + "$Vertx34Advice"); | ||
transformer.applyAdviceToMethod( | ||
isConstructor() | ||
.and(takesArgument(1, boolean.class)) | ||
.and(takesArgument(4, String.class)) | ||
.and(takesArgument(5, int.class)), | ||
HttpRequestImplInstrumentation.class.getName() + "$Vertx37Advice"); | ||
} | ||
|
||
public static class Vertx30Advice { | ||
@Advice.OnMethodExit(suppress = Throwable.class) | ||
public static void attachRequestInfo( | ||
@Advice.This HttpClientRequest request, | ||
@Advice.Argument(0) HttpClientImpl client, | ||
@Advice.Argument(2) String host, | ||
@Advice.Argument(3) int port) { | ||
HttpClientOptions httpClientOptions = | ||
VirtualField.find(HttpClientImpl.class, HttpClientOptions.class).get(client); | ||
VirtualField.find(HttpClientRequest.class, VertxRequestInfo.class) | ||
.set( | ||
request, | ||
VertxRequestInfo.create( | ||
httpClientOptions != null ? httpClientOptions.isSsl() : false, host, port)); | ||
} | ||
} | ||
|
||
public static class Vertx34Advice { | ||
@Advice.OnMethodExit(suppress = Throwable.class) | ||
public static void attachRequestInfo( | ||
@Advice.This HttpClientRequest request, | ||
@Advice.Argument(1) boolean ssl, | ||
@Advice.Argument(3) String host, | ||
@Advice.Argument(4) int port) { | ||
VirtualField.find(HttpClientRequest.class, VertxRequestInfo.class) | ||
.set(request, VertxRequestInfo.create(ssl, host, port)); | ||
} | ||
} | ||
|
||
public static class Vertx37Advice { | ||
@Advice.OnMethodExit(suppress = Throwable.class) | ||
public static void attachRequestInfo( | ||
@Advice.This HttpClientRequest request, | ||
@Advice.Argument(1) boolean ssl, | ||
@Advice.Argument(4) String host, | ||
@Advice.Argument(5) int port) { | ||
VirtualField.find(HttpClientRequest.class, VertxRequestInfo.class) | ||
.set(request, VertxRequestInfo.create(ssl, host, port)); | ||
} | ||
} | ||
} |
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
22 changes: 22 additions & 0 deletions
22
...n/java/io/opentelemetry/javaagent/instrumentation/vertx/v3_0/client/VertxRequestInfo.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,22 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.javaagent.instrumentation.vertx.v3_0.client; | ||
|
||
import com.google.auto.value.AutoValue; | ||
|
||
@AutoValue | ||
public abstract class VertxRequestInfo { | ||
|
||
public static VertxRequestInfo create(boolean ssl, String host, int port) { | ||
return new AutoValue_VertxRequestInfo(ssl, host, port); | ||
} | ||
|
||
public abstract boolean isSsl(); | ||
|
||
public abstract String getHost(); | ||
|
||
public abstract int getPort(); | ||
} |
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
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