From 7c5f922d28642b2a3e206da7cf337337480af4d7 Mon Sep 17 00:00:00 2001 From: Shashank Patidar Date: Mon, 18 Mar 2024 22:28:01 +0530 Subject: [PATCH] fix netty client --- .../build.gradle.kts | 4 - .../apache-httpclient-4.0/build.gradle.kts | 1 - instrumentation/build.gradle.kts | 1 - instrumentation/java-streams/build.gradle.kts | 1 - .../jaxrs-client-2.0/build.gradle.kts | 4 - .../MicronautClientInstrumentationTest.java | 10 ++- ...tractNetty40ServerInstrumentationTest.java | 10 ++- .../netty/netty-4.1/build.gradle.kts | 2 +- ...tractNetty41ServerInstrumentationTest.java | 10 ++- .../okhttp/okhttp-3.0/build.gradle.kts | 1 - .../servlet/servlet-3.0/build.gradle.kts | 6 -- .../servlet/servlet-rw/build.gradle.kts | 1 - instrumentation/spark-2.3/build.gradle.kts | 4 - .../spring-webflux-5.0/build.gradle.kts | 3 - instrumentation/struts-2.3/build.gradle.kts | 7 -- .../undertow/undertow-1.4/build.gradle.kts | 5 -- .../vertx/vertx-web-3.0/build.gradle.kts | 3 - .../extensions/HypertracePropertySource.java | 85 +++++++++++++++++++ .../agent/smoketest/AppServerTest.groovy | 6 -- .../agent/testing/AbstractHttpClientTest.java | 53 ++++++++++-- .../agent/testing/TestOtlpReceiver.java | 4 +- 21 files changed, 157 insertions(+), 64 deletions(-) create mode 100644 otel-extensions/src/main/java/org/hypertrace/agent/otel/extensions/HypertracePropertySource.java diff --git a/instrumentation/apache-httpasyncclient-4.1/build.gradle.kts b/instrumentation/apache-httpasyncclient-4.1/build.gradle.kts index 5add4160..f52b85ea 100644 --- a/instrumentation/apache-httpasyncclient-4.1/build.gradle.kts +++ b/instrumentation/apache-httpasyncclient-4.1/build.gradle.kts @@ -32,10 +32,6 @@ dependencies { api(project(":instrumentation:apache-httpclient-4.0")) implementation("io.opentelemetry.javaagent.instrumentation:opentelemetry-javaagent-apache-httpasyncclient-4.1:${versions["opentelemetry_java_agent"]}") - testImplementation("io.opentelemetry.javaagent.instrumentation:opentelemetry-javaagent-apache-httpclient-4.0:${versions["opentelemetry_java_agent"]}") - testImplementation("io.opentelemetry.instrumentation:opentelemetry-instrumentation-api-semconv:${versions["opentelemetry_api_semconv"]}") library("org.apache.httpcomponents:httpasyncclient:4.1") testImplementation(project(":testing-common")) - testImplementation("io.opentelemetry.javaagent:opentelemetry-testing-common:1.33.0-alpha") } - diff --git a/instrumentation/apache-httpclient-4.0/build.gradle.kts b/instrumentation/apache-httpclient-4.0/build.gradle.kts index 3485ea30..9c4503a4 100644 --- a/instrumentation/apache-httpclient-4.0/build.gradle.kts +++ b/instrumentation/apache-httpclient-4.0/build.gradle.kts @@ -43,5 +43,4 @@ dependencies { api(project(":instrumentation:java-streams")) library("org.apache.httpcomponents:httpclient:4.0") testImplementation(project(":testing-common")) - testImplementation("io.opentelemetry.instrumentation:opentelemetry-instrumentation-api-semconv:${versions["opentelemetry_api_semconv"]}") } diff --git a/instrumentation/build.gradle.kts b/instrumentation/build.gradle.kts index 30423ce3..01401654 100644 --- a/instrumentation/build.gradle.kts +++ b/instrumentation/build.gradle.kts @@ -93,7 +93,6 @@ subprojects { // Reduce noise in assertion messages since we don't need to verify this in most tests. We check // in smoke tests instead. "-Dotel.javaagent.add-thread-details=false", - "-Dotel.javaagent.experimental.indy=${findProperty("testIndy") == "true"}", // suppress repeated logging of "No metric data to export - skipping export." // since PeriodicMetricReader is configured with a short interval "-Dio.opentelemetry.javaagent.slf4j.simpleLogger.log.io.opentelemetry.sdk.metrics.export.PeriodicMetricReader=INFO", diff --git a/instrumentation/java-streams/build.gradle.kts b/instrumentation/java-streams/build.gradle.kts index bbfe41c4..b1697358 100644 --- a/instrumentation/java-streams/build.gradle.kts +++ b/instrumentation/java-streams/build.gradle.kts @@ -26,5 +26,4 @@ val versions: Map by extra dependencies { implementation("io.opentelemetry.instrumentation:opentelemetry-instrumentation-api:${versions["opentelemetry"]}") testImplementation(project(":testing-common")) - testImplementation("io.opentelemetry.javaagent:opentelemetry-muzzle:${versions["opentelemetry_java_agent"]}") } diff --git a/instrumentation/jaxrs-client-2.0/build.gradle.kts b/instrumentation/jaxrs-client-2.0/build.gradle.kts index 10382a2c..2d504d2b 100644 --- a/instrumentation/jaxrs-client-2.0/build.gradle.kts +++ b/instrumentation/jaxrs-client-2.0/build.gradle.kts @@ -40,11 +40,7 @@ dependencies { testImplementation(project(":testing-common")) testImplementation("org.glassfish.jersey.core:jersey-client:2.27") testImplementation("org.glassfish.jersey.inject:jersey-hk2:2.27") - testImplementation("io.opentelemetry.instrumentation:opentelemetry-instrumentation-api-semconv:${versions["opentelemetry_api_semconv"]}") - testImplementation(project(":instrumentation:apache-httpclient-4.0")) - testImplementation(files(project(":instrumentation:apache-httpclient-4.0").dependencyProject.sourceSets.main.map { it.output })) - testImplementation("io.opentelemetry.javaagent.instrumentation:opentelemetry-javaagent-apache-httpclient-4.0:${versions["opentelemetry_java_agent"]}") testImplementation("org.jboss.resteasy:resteasy-client:3.0.5.Final") // ^ This version has timeouts https://issues.redhat.com/browse/RESTEASY-975 testImplementation("org.apache.cxf:cxf-rt-rs-client:3.1.0") diff --git a/instrumentation/micronaut-1.0/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/micronaut/MicronautClientInstrumentationTest.java b/instrumentation/micronaut-1.0/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/micronaut/MicronautClientInstrumentationTest.java index ca566641..a5c69873 100644 --- a/instrumentation/micronaut-1.0/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/micronaut/MicronautClientInstrumentationTest.java +++ b/instrumentation/micronaut-1.0/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/micronaut/MicronautClientInstrumentationTest.java @@ -69,7 +69,15 @@ public void getJson() throws InterruptedException, TimeoutException { TEST_WRITER.waitForTraces(1); List> traces = - TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_SERVER)); + TEST_WRITER.waitForSpans( + 1, + span -> + !span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT) + || span.getAttributesList().stream() + .noneMatch( + keyValue -> + keyValue.getKey().equals("http.url") + && keyValue.getValue().getStringValue().contains("/get_json"))); Assertions.assertEquals(1, traces.size()); Assertions.assertEquals(1, traces.get(0).size()); Span clientSpan = traces.get(0).get(0); diff --git a/instrumentation/netty/netty-4.0/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_0/server/AbstractNetty40ServerInstrumentationTest.java b/instrumentation/netty/netty-4.0/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_0/server/AbstractNetty40ServerInstrumentationTest.java index c5800d41..edfb04e5 100644 --- a/instrumentation/netty/netty-4.0/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_0/server/AbstractNetty40ServerInstrumentationTest.java +++ b/instrumentation/netty/netty-4.0/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_0/server/AbstractNetty40ServerInstrumentationTest.java @@ -30,11 +30,13 @@ import okhttp3.Response; import okio.Buffer; import org.hypertrace.agent.testing.AbstractInstrumenterTest; -import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public abstract class AbstractNetty40ServerInstrumentationTest extends AbstractInstrumenterTest { public static final String REQUEST_HEADER_NAME = "reqheader"; @@ -43,13 +45,13 @@ public abstract class AbstractNetty40ServerInstrumentationTest extends AbstractI private static int port; private static NettyTestServer nettyTestServer; - @BeforeEach + @BeforeAll private void startServer() throws IOException, InterruptedException { nettyTestServer = createNetty(); port = nettyTestServer.create(); } - @AfterEach + @AfterAll private void stopServer() throws ExecutionException, InterruptedException { nettyTestServer.stopServer(); } diff --git a/instrumentation/netty/netty-4.1/build.gradle.kts b/instrumentation/netty/netty-4.1/build.gradle.kts index 2c9f3cfb..43fb115c 100644 --- a/instrumentation/netty/netty-4.1/build.gradle.kts +++ b/instrumentation/netty/netty-4.1/build.gradle.kts @@ -53,7 +53,7 @@ dependencies { implementation("io.opentelemetry.instrumentation:opentelemetry-instrumentation-api-semconv:${versions["opentelemetry_api_semconv"]}") library("io.netty:netty-codec-http:4.1.0.Final") - testImplementation(project(":testing-common")) + testImplementation(project(":testing-common")) testImplementation("io.netty:netty-handler:4.1.0.Final") testImplementation("org.asynchttpclient:async-http-client:2.1.0") } diff --git a/instrumentation/netty/netty-4.1/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_1/server/AbstractNetty41ServerInstrumentationTest.java b/instrumentation/netty/netty-4.1/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_1/server/AbstractNetty41ServerInstrumentationTest.java index 597709e2..4a312157 100644 --- a/instrumentation/netty/netty-4.1/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_1/server/AbstractNetty41ServerInstrumentationTest.java +++ b/instrumentation/netty/netty-4.1/src/test/java/io/opentelemetry/javaagent/instrumentation/hypertrace/netty/v4_1/server/AbstractNetty41ServerInstrumentationTest.java @@ -30,11 +30,13 @@ import okhttp3.Response; import okio.Buffer; import org.hypertrace.agent.testing.AbstractInstrumenterTest; -import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +@TestInstance(TestInstance.Lifecycle.PER_CLASS) public abstract class AbstractNetty41ServerInstrumentationTest extends AbstractInstrumenterTest { public static final String REQUEST_HEADER_NAME = "reqheader"; @@ -43,13 +45,13 @@ public abstract class AbstractNetty41ServerInstrumentationTest extends AbstractI private static int port; private static NettyTestServer nettyTestServer; - @BeforeEach + @BeforeAll private void startServer() throws IOException, InterruptedException { nettyTestServer = createNetty(); port = nettyTestServer.create(); } - @AfterEach + @AfterAll private void stopServer() throws ExecutionException, InterruptedException { nettyTestServer.stopServer(); } diff --git a/instrumentation/okhttp/okhttp-3.0/build.gradle.kts b/instrumentation/okhttp/okhttp-3.0/build.gradle.kts index a09a03b8..3c6371dc 100644 --- a/instrumentation/okhttp/okhttp-3.0/build.gradle.kts +++ b/instrumentation/okhttp/okhttp-3.0/build.gradle.kts @@ -27,6 +27,5 @@ val versions: Map by extra dependencies { compileOnly("com.squareup.okhttp3:okhttp:3.0.0") - testImplementation("io.opentelemetry.javaagent.instrumentation:opentelemetry-javaagent-okhttp-3.0:${versions["opentelemetry_java_agent"]}") testImplementation(project(":testing-common")) } diff --git a/instrumentation/servlet/servlet-3.0/build.gradle.kts b/instrumentation/servlet/servlet-3.0/build.gradle.kts index 18c84f19..57c1805e 100644 --- a/instrumentation/servlet/servlet-3.0/build.gradle.kts +++ b/instrumentation/servlet/servlet-3.0/build.gradle.kts @@ -33,19 +33,13 @@ val versions: Map by extra dependencies { implementation("io.opentelemetry.javaagent.instrumentation:opentelemetry-javaagent-servlet-common:${versions["opentelemetry_java_agent"]}") implementation("io.opentelemetry.javaagent.instrumentation:opentelemetry-javaagent-servlet-3.0:${versions["opentelemetry_java_agent"]}") // Servlet3Accessor - testImplementation("io.opentelemetry.javaagent.instrumentation:opentelemetry-javaagent-servlet-3.0:${versions["opentelemetry_java_agent"]}") - testImplementation("io.opentelemetry.javaagent:opentelemetry-muzzle:${versions["opentelemetry_java_agent"]}") compileOnly("io.opentelemetry.javaagent:opentelemetry-javaagent-bootstrap:${versions["opentelemetry_java_agent"]}") compileOnly("javax.servlet:javax.servlet-api:3.1.0") - testRuntimeOnly("io.opentelemetry.javaagent.instrumentation:opentelemetry-javaagent-servlet-common-bootstrap:${versions["opentelemetry_java_agent"]}") muzzleBootstrap("io.opentelemetry.javaagent.instrumentation:opentelemetry-javaagent-servlet-common-bootstrap:${versions["opentelemetry_java_agent"]}") - testImplementation(project(":instrumentation:servlet:servlet-rw")) - testImplementation(files(project(":instrumentation:servlet:servlet-rw").dependencyProject.sourceSets.main.map { it.output })) testImplementation(project(":testing-common") as ProjectDependency) { exclude(group = "org.eclipse.jetty", module = "jetty-server") } testImplementation("org.eclipse.jetty:jetty-server:8.1.22.v20160922") testImplementation("org.eclipse.jetty:jetty-servlet:8.1.22.v20160922") - testImplementation("io.opentelemetry.instrumentation:opentelemetry-instrumentation-api-semconv:${versions["opentelemetry_api_semconv"]}") } diff --git a/instrumentation/servlet/servlet-rw/build.gradle.kts b/instrumentation/servlet/servlet-rw/build.gradle.kts index 14143d8f..acb44734 100644 --- a/instrumentation/servlet/servlet-rw/build.gradle.kts +++ b/instrumentation/servlet/servlet-rw/build.gradle.kts @@ -24,6 +24,5 @@ val versions: Map by extra dependencies { testImplementation(project(":testing-common")) - testImplementation("io.opentelemetry.javaagent:opentelemetry-muzzle:${versions["opentelemetry_java_agent"]}") testImplementation("org.eclipse.jetty:jetty-servlet:8.1.22.v20160922") } diff --git a/instrumentation/spark-2.3/build.gradle.kts b/instrumentation/spark-2.3/build.gradle.kts index 672dc1da..f48819b8 100644 --- a/instrumentation/spark-2.3/build.gradle.kts +++ b/instrumentation/spark-2.3/build.gradle.kts @@ -29,14 +29,10 @@ val versions: Map by extra dependencies { api(project(":instrumentation:servlet:servlet-3.0")) - testRuntimeOnly("io.opentelemetry.javaagent.instrumentation:opentelemetry-javaagent-servlet-common-bootstrap:${versions["opentelemetry_java_agent"]}") muzzleBootstrap("io.opentelemetry.javaagent.instrumentation:opentelemetry-javaagent-servlet-common-bootstrap:${versions["opentelemetry_java_agent"]}") compileOnly("com.sparkjava:spark-core:2.3") - testImplementation(project(":instrumentation:servlet:servlet-rw")) - testImplementation(files(project(":instrumentation:servlet:servlet-rw").dependencyProject.sourceSets.main.map { it.output })) testImplementation(project(":testing-common")) testImplementation("com.sparkjava:spark-core:2.3") - testImplementation("io.opentelemetry.instrumentation:opentelemetry-instrumentation-api-semconv:${versions["opentelemetry_api_semconv"]}") } diff --git a/instrumentation/spring/spring-webflux-5.0/build.gradle.kts b/instrumentation/spring/spring-webflux-5.0/build.gradle.kts index 091a9617..0d1da768 100644 --- a/instrumentation/spring/spring-webflux-5.0/build.gradle.kts +++ b/instrumentation/spring/spring-webflux-5.0/build.gradle.kts @@ -16,13 +16,10 @@ configurations.testRuntimeClasspath { dependencies { testImplementation(project(":testing-common")) - testImplementation(project(":instrumentation:netty:netty-4.1")) - testImplementation(files(project(":instrumentation:netty:netty-4.1").dependencyProject.sourceSets.main.map { it.output })) testImplementation("org.springframework:spring-webflux:5.0.0.RELEASE") testImplementation("io.projectreactor.ipc:reactor-netty:0.7.0.RELEASE") testImplementation("org.springframework.boot:spring-boot-starter-webflux:2.0.0.RELEASE") testImplementation("org.springframework.boot:spring-boot-starter-test:2.0.0.RELEASE") testImplementation("org.springframework.boot:spring-boot-starter-reactor-netty:2.0.0.RELEASE") - testImplementation("io.opentelemetry.instrumentation:opentelemetry-instrumentation-api-semconv:${versions["opentelemetry_api_semconv"]}") } diff --git a/instrumentation/struts-2.3/build.gradle.kts b/instrumentation/struts-2.3/build.gradle.kts index 6fd40ab9..04ac3557 100644 --- a/instrumentation/struts-2.3/build.gradle.kts +++ b/instrumentation/struts-2.3/build.gradle.kts @@ -6,20 +6,13 @@ plugins { val versions: Map by extra dependencies { - testImplementation(project(":instrumentation:servlet:servlet-rw")) - testImplementation(files(project(":instrumentation:servlet:servlet-rw").dependencyProject.sourceSets.main.map { it.output })) - testImplementation(project(":instrumentation:servlet:servlet-3.0")) - testImplementation(files(project(":instrumentation:servlet:servlet-3.0").dependencyProject.sourceSets.main.map { it.output })) testImplementation(project(":testing-common") as ProjectDependency) { exclude(group = "org.eclipse.jetty", module = "jetty-server") } - testImplementation("io.opentelemetry.javaagent.instrumentation:opentelemetry-javaagent-servlet-3.0:${versions["opentelemetry_java_agent"]}") - testRuntimeOnly("io.opentelemetry.javaagent.instrumentation:opentelemetry-javaagent-servlet-common-bootstrap:${versions["opentelemetry_java_agent"]}") testImplementation("org.apache.struts:struts2-core:2.3.1") testImplementation("org.apache.struts:struts2-json-plugin:2.3.1") testImplementation("org.eclipse.jetty:jetty-server:8.0.0.v20110901") testImplementation("org.eclipse.jetty:jetty-servlet:8.0.0.v20110901") testImplementation("javax.servlet:javax.servlet-api:3.0.1") testImplementation("javax.servlet:jsp-api:2.0") - testImplementation("io.opentelemetry.instrumentation:opentelemetry-instrumentation-api-semconv:${versions["opentelemetry_api_semconv"]}") } diff --git a/instrumentation/undertow/undertow-1.4/build.gradle.kts b/instrumentation/undertow/undertow-1.4/build.gradle.kts index d762556a..af029001 100644 --- a/instrumentation/undertow/undertow-1.4/build.gradle.kts +++ b/instrumentation/undertow/undertow-1.4/build.gradle.kts @@ -32,9 +32,4 @@ dependencies { testImplementation(project(":testing-common")) testImplementation("javax.servlet:javax.servlet-api:3.1.0") testImplementation("io.undertow:undertow-servlet:2.0.0.Final") - testImplementation("io.opentelemetry.instrumentation:opentelemetry-instrumentation-api-semconv:${versions["opentelemetry_api_semconv"]}") - testRuntimeOnly(project(":instrumentation:servlet:servlet-3.0")) - testRuntimeOnly(project(":instrumentation:undertow:undertow-servlet-1.4")) - testRuntimeOnly("io.opentelemetry.javaagent.instrumentation:opentelemetry-javaagent-servlet-common-bootstrap:${versions["opentelemetry_java_agent"]}") } - diff --git a/instrumentation/vertx/vertx-web-3.0/build.gradle.kts b/instrumentation/vertx/vertx-web-3.0/build.gradle.kts index efd0f004..942e1e73 100644 --- a/instrumentation/vertx/vertx-web-3.0/build.gradle.kts +++ b/instrumentation/vertx/vertx-web-3.0/build.gradle.kts @@ -33,8 +33,6 @@ dependencies { library("io.vertx:vertx-web:3.0.0") testImplementation(project(":testing-common")) - testImplementation(project(":instrumentation:netty:netty-4.0")) - testImplementation(files(project(":instrumentation:netty:netty-4.0").dependencyProject.sourceSets.main.map { it.output })) testImplementation("io.netty:netty-codec-http:${nettyVersion}") { version { @@ -67,4 +65,3 @@ dependencies { } } } - diff --git a/otel-extensions/src/main/java/org/hypertrace/agent/otel/extensions/HypertracePropertySource.java b/otel-extensions/src/main/java/org/hypertrace/agent/otel/extensions/HypertracePropertySource.java new file mode 100644 index 00000000..c4a1a625 --- /dev/null +++ b/otel-extensions/src/main/java/org/hypertrace/agent/otel/extensions/HypertracePropertySource.java @@ -0,0 +1,85 @@ +/* + * Copyright The Hypertrace Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.hypertrace.agent.otel.extensions; + +import com.google.auto.service.AutoService; +import io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizer; +import io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizerProvider; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; + +@AutoService(AutoConfigurationCustomizerProvider.class) +public final class HypertracePropertySource implements AutoConfigurationCustomizerProvider { + + /** + * Add all the properties needed at runtime by default. We have added the properties to disable + * all instrumentations by default. Only enable the ones we support. For testing these, add all + * the following properties in static block in + * org.hypertrace.agent.testing.AbstractInstrumenterTest in hypertrace javaagent repo and run all + * the tests in hypertrace javaagent instrumentation. + */ + public Map getProperties() { + final Map configProperties = new HashMap<>(); + // Make everything off by default + configProperties.put("otel.instrumentation.common.default-enabled", "false"); + + // Enable the server instrumentations that we support(and need) in hypertrace + configProperties.put("otel.instrumentation.netty.enabled", "true"); + configProperties.put("otel.instrumentation.servlet.enabled", "true"); + configProperties.put("otel.instrumentation.vertx-web.enabled", "true"); + configProperties.put("otel.instrumentation.undertow.enabled", "true"); + configProperties.put("otel.instrumentation.grpc.enabled", "true"); + + // Enable the client instrumentations that we support(and need) in hypertrace + configProperties.put("otel.instrumentation.apache-httpasyncclient.enabled", "true"); + configProperties.put("otel.instrumentation.apache-httpclient.enabled", "true"); + configProperties.put("otel.instrumentation.okhttp.enabled", "true"); + configProperties.put("otel.instrumentation.http-url-connection.enabled", "true"); + configProperties.put("otel.instrumentation.vertx.enabled", "true"); + + // Enable the db instrumentations + configProperties.put("otel.instrumentation.apache-dbcp.enabled", "true"); + configProperties.put("otel.instrumentation.jdbc.enabled", "true"); + configProperties.put("otel.instrumentation.jdbc-datasource.enabled", "true"); + configProperties.put("otel.instrumentation.mongo.enabled", "true"); + configProperties.put("otel.instrumentation.r2dbc.enabled", "true"); + configProperties.put("otel.instrumentation.tomcat-jdbc.enabled", "true"); + configProperties.put("otel.instrumentation.vibur-dbcp.enabled", "true"); + + // Enable all hypertrace instrumentations + configProperties.put("otel.instrumentation.inputstream.enabled", "true"); + configProperties.put("otel.instrumentation.outputstream.enabled", "true"); + configProperties.put("otel.instrumentation.ht.enabled", "true"); + + // Enable otel specific instrumentations + configProperties.put("otel.instrumentation.methods.enabled", "true"); + configProperties.put("otel.instrumentation.external-annotations.enabled", "true"); + configProperties.put( + "otel.instrumentation.opentelemetry-extension-annotations.enabled", "true"); + configProperties.put( + "otel.instrumentation.opentelemetry-instrumentation-annotations.enabled", "true"); + configProperties.put("otel.instrumentation.opentelemetry-api.enabled", "true"); + + return Collections.unmodifiableMap(configProperties); + } + + @Override + public void customize(AutoConfigurationCustomizer autoConfigurationCustomizer) { + autoConfigurationCustomizer.addPropertiesSupplier(this::getProperties); + } +} diff --git a/smoke-tests/src/test/groovy/org/hypertrace/agent/smoketest/AppServerTest.groovy b/smoke-tests/src/test/groovy/org/hypertrace/agent/smoketest/AppServerTest.groovy index e98de3e9..290b3bce 100644 --- a/smoke-tests/src/test/groovy/org/hypertrace/agent/smoketest/AppServerTest.groovy +++ b/smoke-tests/src/test/groovy/org/hypertrace/agent/smoketest/AppServerTest.groovy @@ -5,16 +5,10 @@ package org.hypertrace.agent.smoketest -import io.opentelemetry.proto.common.v1.KeyValue import okhttp3.MediaType import okhttp3.RequestBody -import spock.lang.Ignore import spock.lang.IgnoreIf -import java.util.function.Function -import java.util.function.Predicate -import java.util.stream.Stream - import static org.junit.Assume.assumeTrue import io.opentelemetry.proto.trace.v1.Span diff --git a/testing-common/src/main/java/org/hypertrace/agent/testing/AbstractHttpClientTest.java b/testing-common/src/main/java/org/hypertrace/agent/testing/AbstractHttpClientTest.java index 1c04c0cf..d71cdd21 100644 --- a/testing-common/src/main/java/org/hypertrace/agent/testing/AbstractHttpClientTest.java +++ b/testing-common/src/main/java/org/hypertrace/agent/testing/AbstractHttpClientTest.java @@ -113,7 +113,14 @@ public void postJson_echo() // exclude server spans traces = TEST_WRITER.waitForSpans( - 1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_SERVER)); + 1, + span -> + !span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT) + || span.getAttributesList().stream() + .noneMatch( + keyValue -> + keyValue.getKey().equals("http.url") + && keyValue.getValue().getStringValue().contains("/echo"))); } Assertions.assertEquals(1, traces.size()); Span clientSpan = traces.get(0).get(0); @@ -154,7 +161,14 @@ public void postUrlEncoded_echo() } else { traces = TEST_WRITER.waitForSpans( - 1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_SERVER)); + 1, + span -> + !span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT) + || span.getAttributesList().stream() + .noneMatch( + keyValue -> + keyValue.getKey().equals("http.url") + && keyValue.getValue().getStringValue().contains("/echo"))); } Assertions.assertEquals(1, traces.size()); Span clientSpan = traces.get(0).get(0); @@ -186,7 +200,15 @@ public void postPlainText_echo() TEST_WRITER.waitForTraces(1); List> traces = - TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_SERVER)); + TEST_WRITER.waitForSpans( + 1, + span -> + !span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT) + || span.getAttributesList().stream() + .noneMatch( + keyValue -> + keyValue.getKey().equals("http.url") + && keyValue.getValue().getStringValue().contains("/echo"))); Assertions.assertEquals(1, traces.size()); Assertions.assertEquals(1, traces.get(0).size()); Span clientSpan = traces.get(0).get(0); @@ -207,7 +229,18 @@ public void getNoContent() TEST_WRITER.waitForTraces(1); List> traces = - TEST_WRITER.waitForSpans(1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_SERVER)); + TEST_WRITER.waitForSpans( + 1, + span -> + !span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT) + || span.getAttributesList().stream() + .noneMatch( + keyValue -> + keyValue.getKey().equals("http.url") + && keyValue + .getValue() + .getStringValue() + .contains("/get_no_content"))); Assertions.assertEquals(1, traces.size()); Assertions.assertEquals(1, traces.get(0).size()); Span clientSpan = traces.get(0).get(0); @@ -235,7 +268,17 @@ public void getJson() } else { traces = TEST_WRITER.waitForSpans( - 1, span -> span.getKind().equals(Span.SpanKind.SPAN_KIND_SERVER)); + 1, + span -> + !span.getKind().equals(Span.SpanKind.SPAN_KIND_CLIENT) + || span.getAttributesList().stream() + .noneMatch( + keyValue -> + keyValue.getKey().equals("http.url") + && keyValue + .getValue() + .getStringValue() + .contains("/get_json"))); } Assertions.assertEquals(1, traces.size()); diff --git a/testing-common/src/main/java/org/hypertrace/agent/testing/TestOtlpReceiver.java b/testing-common/src/main/java/org/hypertrace/agent/testing/TestOtlpReceiver.java index e857dce0..0d82597b 100644 --- a/testing-common/src/main/java/org/hypertrace/agent/testing/TestOtlpReceiver.java +++ b/testing-common/src/main/java/org/hypertrace/agent/testing/TestOtlpReceiver.java @@ -151,7 +151,7 @@ public void waitForTraces(int number) throws InterruptedException, TimeoutExcept public List> waitForTraces(int number, Predicate> excludes) throws InterruptedException, TimeoutException { synchronized (tracesLock) { - long remainingWaitMillis = TimeUnit.SECONDS.toMillis(20); + long remainingWaitMillis = TimeUnit.SECONDS.toMillis(31); List> traces = getCompletedAndFilteredTraces(excludes, span -> false); while (traces.size() < number && remainingWaitMillis > 0) { Stopwatch stopwatch = Stopwatch.createStarted(); @@ -189,7 +189,7 @@ public List> waitForSpans(int number) throws InterruptedException, Ti public List> waitForSpans(int number, Predicate excludes) throws InterruptedException, TimeoutException { synchronized (tracesLock) { - long remainingWaitMillis = TimeUnit.SECONDS.toMillis(20); + long remainingWaitMillis = TimeUnit.SECONDS.toMillis(31); List> traces = getCompletedAndFilteredTraces(spans -> false, excludes); while (spansCount(traces) < number && remainingWaitMillis > 0) {