Support reactor netty HttpClient.from construction
MODIFY
instrumentation/reactor-netty-0.9/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v0_9/ReactorNettyInstrumentationModule.java
instrumentation/reactor-netty-0.9/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v0_9/ReactorNettyInstrumentationModule.java
@@ -10,6 +10,7 @@ import static java.util.Collections.singletonList;
import static java.util.Collections.singletonMap;
import static net.bytebuddy.matcher.ElementMatchers.isStatic;
import static net.bytebuddy.matcher.ElementMatchers.named;
+import static net.bytebuddy.matcher.ElementMatchers.namedOneOf;
import com.google.auto.service.AutoService;
import io.netty.bootstrap.Bootstrap;
@@ -64,7 +65,7 @@ public class ReactorNettyInstrumentationModule extends InstrumentationModule {
@Override
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
return singletonMap(
- isStatic().and(named("create").or(named("newConnection"))),
+ isStatic().and(namedOneOf("create", "newConnection", "from")),
ReactorNettyInstrumentationModule.class.getName() + "$CreateAdvice");
}
}

ADD
instrumentation/reactor-netty-0.9/javaagent/src/test/groovy/AbstractReactorNettyHttpClientTest.groovy
+/*
+ * Copyright The OpenTelemetry Authors
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+import io.opentelemetry.instrumentation.test.AgentTestTrait
+import io.opentelemetry.instrumentation.test.base.HttpClientTest
+import reactor.netty.http.client.HttpClient
+import reactor.netty.http.client.HttpClientResponse
+
+abstract class AbstractReactorNettyHttpClientTest extends HttpClientTest implements AgentTestTrait {
+
+ @Override
+ boolean testRedirects() {
+ false
+ }
+
+ @Override
+ boolean testConnectionFailure() {
+ false
+ }
+
+ @Override
+ boolean testRemoteConnection() {
+ false
+ }
+
+ @Override
+ String userAgent() {
+ return "ReactorNetty"
+ }
+
+ @Override
+ int doRequest(String method, URI uri, Map<String, String> headers = [:], Closure callback = null) {
+ HttpClientResponse resp = createHttpClient()
+ .followRedirect(true)
+ .headers({ h -> headers.each { k, v -> h.add(k, v) } })
+ .baseUrl(server.address.toString())
+ ."${method.toLowerCase()}"()
+ .uri(uri.toString())
+ .response()
+ .block()
+ if (callback != null) {
+ callback.call()
+ }
+ return resp.status().code()
+ }
+
+ abstract HttpClient createHttpClient()
+}

MODIFY
instrumentation/reactor-netty-0.9/javaagent/src/test/groovy/ReactorNettyHttpClientTest.groovy
instrumentation/reactor-netty-0.9/javaagent/src/test/groovy/ReactorNettyHttpClientTest.groovy
* SPDX-License-Identifier: Apache-2.0
*/
-import io.opentelemetry.instrumentation.test.AgentTestTrait
-import io.opentelemetry.instrumentation.test.base.HttpClientTest
import io.opentelemetry.instrumentation.test.base.SingleConnection
import java.util.concurrent.ExecutionException
import java.util.concurrent.TimeoutException
import reactor.netty.http.client.HttpClient
-import reactor.netty.http.client.HttpClientResponse
-class ReactorNettyHttpClientTest extends HttpClientTest implements AgentTestTrait {
+class ReactorNettyHttpClientTest extends AbstractReactorNettyHttpClientTest {
- @Override
- boolean testRedirects() {
- false
- }
-
- @Override
- boolean testConnectionFailure() {
- false
- }
-
- @Override
- boolean testRemoteConnection() {
- false
- }
-
- @Override
- String userAgent() {
- return "ReactorNetty"
- }
-
- @Override
- int doRequest(String method, URI uri, Map<String, String> headers = [:], Closure callback = null) {
- HttpClientResponse resp = HttpClient.create()
- .followRedirect(true)
- .headers({ h -> headers.each { k, v -> h.add(k, v) } })
- .baseUrl(server.address.toString())
- ."${method.toLowerCase()}"()
- .uri(uri.toString())
- .response()
- .block()
- if (callback != null) {
- callback.call()
- }
- return resp.status().code()
+ HttpClient createHttpClient() {
+ return HttpClient.create()
}
@Override
@@ -76,5 +41,4 @@ class ReactorNettyHttpClientTest extends HttpClientTest implements AgentTestTrai
}
}
}
-
}

ADD
instrumentation/reactor-netty-0.9/javaagent/src/test/groovy/ReactorNettyHttpClientUsingFromTest.groovy
+/*
+ * Copyright The OpenTelemetry Authors
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+import reactor.netty.http.client.HttpClient
+import reactor.netty.tcp.TcpClient
+
+class ReactorNettyHttpClientUsingFromTest extends AbstractReactorNettyHttpClientTest {
+
+ HttpClient createHttpClient() {
+ return HttpClient.from(TcpClient.create())
+ }
+}

MODIFY
instrumentation/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyInstrumentationModule.java
instrumentation/reactor-netty-1.0/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/reactornetty/v1_0/ReactorNettyInstrumentationModule.java
@@ -10,6 +10,7 @@ import static java.util.Collections.singletonList;
import static java.util.Collections.singletonMap;
import static net.bytebuddy.matcher.ElementMatchers.isStatic;
import static net.bytebuddy.matcher.ElementMatchers.named;
+import static net.bytebuddy.matcher.ElementMatchers.namedOneOf;
import com.google.auto.service.AutoService;
import io.opentelemetry.context.Context;
@@ -63,7 +64,7 @@ public class ReactorNettyInstrumentationModule extends InstrumentationModule {
@Override
public Map<? extends ElementMatcher<? super MethodDescription>, String> transformers() {
return singletonMap(
- isStatic().and(named("create").or(named("newConnection"))),
+ isStatic().and(namedOneOf("create", "newConnection", "from")),
ReactorNettyInstrumentationModule.class.getName() + "$CreateAdvice");
}
}

ADD
instrumentation/reactor-netty-1.0/javaagent/src/test/groovy/AbstractReactorNettyHttpClientTest.groovy
+/*
+ * Copyright The OpenTelemetry Authors
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+import io.opentelemetry.instrumentation.test.AgentTestTrait
+import io.opentelemetry.instrumentation.test.base.HttpClientTest
+import reactor.netty.http.client.HttpClient
+import reactor.netty.http.client.HttpClientResponse
+
+abstract class AbstractReactorNettyHttpClientTest extends HttpClientTest implements AgentTestTrait {
+
+ @Override
+ boolean testRedirects() {
+ false
+ }
+
+ @Override
+ boolean testConnectionFailure() {
+ false
+ }
+
+ @Override
+ boolean testRemoteConnection() {
+ false
+ }
+
+ @Override
+ String userAgent() {
+ return "ReactorNetty"
+ }
+
+ @Override
+ int doRequest(String method, URI uri, Map<String, String> headers = [:], Closure callback = null) {
+ HttpClientResponse resp = createHttpClient()
+ .followRedirect(true)
+ .headers({ h -> headers.each { k, v -> h.add(k, v) } })
+ .baseUrl(server.address.toString())
+ ."${method.toLowerCase()}"()
+ .uri(uri.toString())
+ .response()
+ .block()
+ if (callback != null) {
+ callback.call()
+ }
+ return resp.status().code()
+ }
+
+ abstract HttpClient createHttpClient()
+}

MODIFY
instrumentation/reactor-netty-1.0/javaagent/src/test/groovy/ReactorNettyHttpClientTest.groovy
instrumentation/reactor-netty-1.0/javaagent/src/test/groovy/ReactorNettyHttpClientTest.groovy
* SPDX-License-Identifier: Apache-2.0
*/
-import io.opentelemetry.instrumentation.test.AgentTestTrait
-import io.opentelemetry.instrumentation.test.base.HttpClientTest
import io.opentelemetry.instrumentation.test.base.SingleConnection
import java.util.concurrent.ExecutionException
import java.util.concurrent.TimeoutException
import reactor.netty.http.client.HttpClient
-import reactor.netty.http.client.HttpClientResponse
-class ReactorNettyHttpClientTest extends HttpClientTest implements AgentTestTrait {
+class ReactorNettyHttpClientTest extends AbstractReactorNettyHttpClientTest {
- @Override
- boolean testRedirects() {
- false
- }
-
- @Override
- boolean testConnectionFailure() {
- false
- }
-
- @Override
- boolean testRemoteConnection() {
- false
- }
-
- @Override
- String userAgent() {
- return "ReactorNetty"
- }
-
- @Override
- int doRequest(String method, URI uri, Map<String, String> headers = [:], Closure callback = null) {
- HttpClientResponse resp = HttpClient.create()
- .followRedirect(true)
- .headers({ h -> headers.each { k, v -> h.add(k, v) } })
- .baseUrl(server.address.toString())
- ."${method.toLowerCase()}"()
- .uri(uri.toString())
- .response()
- .block()
- if (callback != null) {
- callback.call()
- }
- return resp.status().code()
+ HttpClient createHttpClient() {
+ return HttpClient.create()
}
@Override

ADD
instrumentation/reactor-netty-1.0/javaagent/src/test/groovy/ReactorNettyHttpClientUsingFromTest.groovy
+/*
+ * Copyright The OpenTelemetry Authors
+ * SPDX-License-Identifier: Apache-2.0
+ */
+
+import reactor.netty.http.client.HttpClient
+import reactor.netty.tcp.TcpClient
+
+class ReactorNettyHttpClientUsingFromTest extends AbstractReactorNettyHttpClientTest {
+
+ HttpClient createHttpClient() {
+ return HttpClient.from(TcpClient.create())
+ }
+}

Support reactor netty HttpClient.from construction (#2650)