Skip to content

Commit

Permalink
Merge pull request #8 from gsmet/jaeger-1.0.0
Browse files Browse the repository at this point in the history
Use quarkus-jaeger 1.0.0 and fix groupId in quickstart module
  • Loading branch information
gsmet authored Nov 23, 2023
2 parents 659803d + 04654ab commit 5e23e4a
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 60 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.quarkus.smallrye.opentracing.deployment;

import io.opentracing.mock.MockTracer;
import io.opentracing.util.GlobalTracer;

public class TracerHolder {

public static MockTracer mockTracer = new MockTracer();

static {
GlobalTracer.registerIfAbsent(mockTracer);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
import org.junit.jupiter.api.extension.RegisterExtension;

import io.opentracing.mock.MockSpan;
import io.opentracing.mock.MockTracer;
import io.opentracing.util.GlobalTracer;
import io.opentracing.util.GlobalTracerTestUtil;
import io.quarkus.test.QuarkusUnitTest;
import io.restassured.RestAssured;
Expand All @@ -31,18 +29,14 @@ public class TracingTest {
.addClass(Service.class)
.addClass(RestService.class)
.addClass(Fruit.class)
.addClass(TracerHolder.class)
.addAsResource("application.properties")
.addAsResource("import.sql")
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"));

static MockTracer mockTracer = new MockTracer();
static {
GlobalTracer.registerIfAbsent(mockTracer);
}

@BeforeEach
public void before() {
mockTracer.reset();
TracerHolder.mockTracer.reset();
}

@AfterAll
Expand All @@ -57,9 +51,9 @@ public void testSingleServerRequest() {
RestAssured.when().get("/hello")
.then()
.statusCode(200);
Assertions.assertEquals(1, mockTracer.finishedSpans().size());
Assertions.assertEquals(1, TracerHolder.mockTracer.finishedSpans().size());
Assertions.assertEquals("GET:io.quarkus.smallrye.opentracing.deployment.TestResource.hello",
mockTracer.finishedSpans().get(0).operationName());
TracerHolder.mockTracer.finishedSpans().get(0).operationName());
} finally {
RestAssured.reset();
}
Expand All @@ -72,11 +66,11 @@ public void testCDI() {
RestAssured.when().get("/cdi")
.then()
.statusCode(200);
Assertions.assertEquals(2, mockTracer.finishedSpans().size());
Assertions.assertEquals(2, TracerHolder.mockTracer.finishedSpans().size());
Assertions.assertEquals("io.quarkus.smallrye.opentracing.deployment.Service.foo",
mockTracer.finishedSpans().get(0).operationName());
TracerHolder.mockTracer.finishedSpans().get(0).operationName());
Assertions.assertEquals("GET:io.quarkus.smallrye.opentracing.deployment.TestResource.cdi",
mockTracer.finishedSpans().get(1).operationName());
TracerHolder.mockTracer.finishedSpans().get(1).operationName());
} finally {
RestAssured.reset();
}
Expand All @@ -89,12 +83,12 @@ public void testMPRestClient() {
RestAssured.when().get("/restClient")
.then()
.statusCode(200);
Assertions.assertEquals(3, mockTracer.finishedSpans().size());
Assertions.assertEquals(3, TracerHolder.mockTracer.finishedSpans().size());
Assertions.assertEquals("GET:io.quarkus.smallrye.opentracing.deployment.TestResource.hello",
mockTracer.finishedSpans().get(0).operationName());
Assertions.assertEquals("GET", mockTracer.finishedSpans().get(1).operationName());
TracerHolder.mockTracer.finishedSpans().get(0).operationName());
Assertions.assertEquals("GET", TracerHolder.mockTracer.finishedSpans().get(1).operationName());
Assertions.assertEquals("GET:io.quarkus.smallrye.opentracing.deployment.TestResource.restClient",
mockTracer.finishedSpans().get(2).operationName());
TracerHolder.mockTracer.finishedSpans().get(2).operationName());
} finally {
RestAssured.reset();
}
Expand All @@ -109,8 +103,8 @@ public void testContextPropagationInFaultTolerance() {
.statusCode(200)
.body(equalTo("fallback"));
Awaitility.await().atMost(5, TimeUnit.SECONDS)
.until(() -> mockTracer.finishedSpans().size() == 5);
List<MockSpan> spans = mockTracer.finishedSpans();
.until(() -> TracerHolder.mockTracer.finishedSpans().size() == 5);
List<MockSpan> spans = TracerHolder.mockTracer.finishedSpans();

Assertions.assertEquals(5, spans.size());
for (MockSpan mockSpan : spans) {
Expand Down Expand Up @@ -143,20 +137,20 @@ public void testJPA() {
.body("name[0]", equalTo("Apple"))
.body("name[1]", equalTo("Banana"))
.body("name[2]", equalTo("Cherry"));
List<MockSpan> spans = mockTracer.finishedSpans();
List<MockSpan> spans = TracerHolder.mockTracer.finishedSpans();

Assertions.assertEquals(3, spans.size());
for (MockSpan mockSpan : spans) {
Assertions.assertEquals(spans.get(0).context().traceId(), mockSpan.context().traceId());
}
MockSpan firstSpan = mockTracer.finishedSpans().get(0);
MockSpan firstSpan = TracerHolder.mockTracer.finishedSpans().get(0);
Assertions.assertEquals("Query", firstSpan.operationName());
Assertions.assertTrue(firstSpan.tags().containsKey("db.statement"));
Assertions.assertTrue(firstSpan.tags().get("db.statement").toString().contains("known_fruits"));
Assertions.assertEquals("io.quarkus.smallrye.opentracing.deployment.Service.getFruits",
mockTracer.finishedSpans().get(1).operationName());
TracerHolder.mockTracer.finishedSpans().get(1).operationName());
Assertions.assertEquals("GET:io.quarkus.smallrye.opentracing.deployment.TestResource.jpa",
mockTracer.finishedSpans().get(2).operationName());
TracerHolder.mockTracer.finishedSpans().get(2).operationName());
} finally {
RestAssured.reset();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@
import com.mongodb.client.MongoClient;

import io.opentracing.mock.MockSpan;
import io.opentracing.mock.MockTracer;
import io.opentracing.util.GlobalTracer;
import io.opentracing.util.GlobalTracerTestUtil;
import io.quarkus.smallrye.opentracing.deployment.TracerHolder;
import io.quarkus.smallrye.opentracing.runtime.integration.MongoTracingCommandListener;
import io.quarkus.test.QuarkusUnitTest;

Expand All @@ -34,17 +33,12 @@ public class MongoTracingCommandListenerTest extends MongoTestBase {
@RegisterExtension
static final QuarkusUnitTest config = new QuarkusUnitTest()
.setArchiveProducer(
() -> ShrinkWrap.create(JavaArchive.class).addClasses(MongoTestBase.class))
() -> ShrinkWrap.create(JavaArchive.class).addClasses(MongoTestBase.class, TracerHolder.class))
.withConfigurationResource("application-tracing-mongo.properties");

static MockTracer mockTracer = new MockTracer();
static {
GlobalTracer.register(mockTracer);
}

@BeforeEach
public void before() {
mockTracer.reset();
TracerHolder.mockTracer.reset();
}

@AfterAll
Expand All @@ -61,12 +55,12 @@ void cleanup() {

@Test
void testClientInitialization() {
assertThat(mockTracer.finishedSpans()).isEmpty();
assertThat(TracerHolder.mockTracer.finishedSpans()).isEmpty();

assertThat(client.listDatabaseNames().first()).isNotEmpty();

assertThat(mockTracer.finishedSpans()).hasSize(1);
MockSpan span = mockTracer.finishedSpans().get(0);
assertThat(TracerHolder.mockTracer.finishedSpans()).hasSize(1);
MockSpan span = TracerHolder.mockTracer.finishedSpans().get(0);
assertThat(span.operationName()).isEqualTo("listDatabases");
}

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<quarkus.version>3.6.0</quarkus.version>
<smallrye-opentracing.version>3.0.3</smallrye-opentracing.version>
<quarkus-jaeger.version>999-SNAPSHOT</quarkus-jaeger.version>
<quarkus-jaeger.version>1.0.0</quarkus-jaeger.version>
<assertj.version>3.24.2</assertj.version>
</properties>
<dependencyManagement>
Expand Down
2 changes: 1 addition & 1 deletion quickstart/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<groupId>io.quarkiverse.opentracing</groupId>
<artifactId>quarkus-smallrye-opentracing</artifactId>
</dependency>
<dependency>
Expand Down

0 comments on commit 5e23e4a

Please sign in to comment.