Skip to content

Commit

Permalink
incooperate PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
hiteshkhatri97 committed Oct 24, 2023
1 parent ae10a36 commit ae03794
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 35 deletions.
40 changes: 40 additions & 0 deletions integration-tests/opentelemetry-jaeger-remote/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,46 @@
<artifactId>jakarta.ws.rs-api</artifactId>
<scope>test</scope>
</dependency>
<!-- Minimal test dependencies to *-deployment artifacts for consistent build order -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-opentelemetry-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-rest-client-reactive-jackson-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-reactive-jackson-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-sdk-extension-jaeger-remote-sampler</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@

import java.time.Duration;

import jakarta.inject.Inject;

import org.awaitility.Awaitility;
import org.eclipse.microprofile.config.ConfigProvider;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;

import com.fasterxml.jackson.core.TreeNode;
import com.fasterxml.jackson.jr.ob.JSON;
import com.fasterxml.jackson.jr.stree.JacksonJrsTreeCodec;
Expand All @@ -12,18 +19,14 @@
import com.github.dockerjava.api.model.ExposedPort;
import com.github.dockerjava.api.model.Ports;
import com.github.dockerjava.core.DockerClientBuilder;

import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.trace.Span;
import jakarta.inject.Inject;
import io.opentelemetry.context.Scope;
import io.quarkus.test.junit.QuarkusTest;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import org.awaitility.Awaitility;
import org.eclipse.microprofile.config.ConfigProvider;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Test;

import io.quarkus.test.junit.QuarkusTest;

@QuarkusTest
public class OTelJaegerRemoteTest {
Expand All @@ -35,18 +38,21 @@ public class OTelJaegerRemoteTest {
private static final String JAEGER_URL = "http://localhost";
@Inject
OpenTelemetry openTelemetry;
private static final DockerClient dockerClient = DockerClientBuilder.getInstance().build();
private static final DockerClient dockerClient;

static {
if(dockerClient.listContainersCmd().exec().stream().noneMatch(container -> container.getNames()[0].equals("/jaeger"))) {
dockerClient = DockerClientBuilder.getInstance().build();
if (dockerClient.listContainersCmd().exec().stream()
.noneMatch(container -> container.getNames()[0].equals("/jaeger"))) {
ExposedPort queryPort = ExposedPort.tcp(QUERY_PORT);
ExposedPort collectorPort = ExposedPort.tcp(COLLECTOR_PORT);
ExposedPort hostPort = ExposedPort.tcp(HEALTH_PORT);
Ports portBindings = new Ports();
portBindings.bind(queryPort, Ports.Binding.bindPort(QUERY_PORT));
portBindings.bind(collectorPort, Ports.Binding.bindPort(COLLECTOR_PORT));
portBindings.bind(hostPort, Ports.Binding.bindPort(HEALTH_PORT));
CreateContainerResponse container = dockerClient.createContainerCmd("ghcr.io/open-telemetry/opentelemetry-java/jaeger:1.32")
CreateContainerResponse container = dockerClient
.createContainerCmd("ghcr.io/open-telemetry/opentelemetry-java/jaeger:1.32")
.withExposedPorts(queryPort, collectorPort, hostPort)
.withHostConfig(newHostConfig().withPortBindings(portBindings))
.withName("jaeger")
Expand All @@ -73,41 +79,38 @@ void testJaegerRemoteIntegration() {
}

private void createTestSpan(OpenTelemetry openTelemetry) {
Span span =
openTelemetry.getTracer(getClass().getCanonicalName()).spanBuilder("Test span").startSpan();
span.addEvent("some event");
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
Span span = openTelemetry.getTracer(getClass().getCanonicalName()).spanBuilder("Test span").startSpan();
try (Scope scope = span.makeCurrent()) {
span.addEvent("Test event");
} catch (Throwable t) {
span.recordException(t);
throw t;
} finally {
span.end();
}
span.end();
}

private static boolean assertJaegerHaveTrace() {
try {

String serviceName = ConfigProvider.getConfig().getConfigValue("quarkus.application.name").getValue();
String url =
String.format(
"%s/api/traces?service=%s",
String.format(JAEGER_URL + ":%d", QUERY_PORT),
serviceName);

Request request =
new Request.Builder()
.url(url)
.header("Content-Type", "application/json")
.header("Accept", "application/json")
.build();
String url = String.format(
"%s/api/traces?service=%s",
String.format(JAEGER_URL + ":%d", QUERY_PORT),
serviceName);

Request request = new Request.Builder()
.url(url)
.header("Content-Type", "application/json")
.header("Accept", "application/json")
.build();

TreeNode json;
try (Response response = client.newCall(request).execute()) {
json =
JSON.builder()
.treeCodec(new JacksonJrsTreeCodec())
.build()
.treeFrom(response.body().byteStream());
json = JSON.builder()
.treeCodec(new JacksonJrsTreeCodec())
.build()
.treeFrom(response.body().byteStream());
}

return json.get("data").get(0).get("traceID") != null;
Expand Down

0 comments on commit ae03794

Please sign in to comment.