Skip to content

Commit

Permalink
fix netty client
Browse files Browse the repository at this point in the history
  • Loading branch information
shashank11p committed Mar 18, 2024
1 parent 2776ee5 commit 7c5f922
Show file tree
Hide file tree
Showing 21 changed files with 157 additions and 64 deletions.
4 changes: 0 additions & 4 deletions instrumentation/apache-httpasyncclient-4.1/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}

1 change: 0 additions & 1 deletion instrumentation/apache-httpclient-4.0/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"]}")
}
1 change: 0 additions & 1 deletion instrumentation/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 0 additions & 1 deletion instrumentation/java-streams/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,4 @@ val versions: Map<String, String> 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"]}")
}
4 changes: 0 additions & 4 deletions instrumentation/jaxrs-client-2.0/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,15 @@ public void getJson() throws InterruptedException, TimeoutException {

TEST_WRITER.waitForTraces(1);
List<List<Span>> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion instrumentation/netty/netty-4.1/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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();
}
Expand Down
1 change: 0 additions & 1 deletion instrumentation/okhttp/okhttp-3.0/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,5 @@ val versions: Map<String, String> 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"))
}
6 changes: 0 additions & 6 deletions instrumentation/servlet/servlet-3.0/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,13 @@ val versions: Map<String, String> 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"]}")
}
1 change: 0 additions & 1 deletion instrumentation/servlet/servlet-rw/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,5 @@ val versions: Map<String, String> 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")
}
4 changes: 0 additions & 4 deletions instrumentation/spark-2.3/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,10 @@ val versions: Map<String, String> 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"]}")
}
3 changes: 0 additions & 3 deletions instrumentation/spring/spring-webflux-5.0/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"]}")
}
7 changes: 0 additions & 7 deletions instrumentation/struts-2.3/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,13 @@ plugins {
val versions: Map<String, String> 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"]}")
}
5 changes: 0 additions & 5 deletions instrumentation/undertow/undertow-1.4/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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"]}")
}

3 changes: 0 additions & 3 deletions instrumentation/vertx/vertx-web-3.0/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -67,4 +65,3 @@ dependencies {
}
}
}

Original file line number Diff line number Diff line change
@@ -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<String, String> getProperties() {
final Map<String, String> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading

0 comments on commit 7c5f922

Please sign in to comment.