diff --git a/extensions/opentelemetry/deployment/pom.xml b/extensions/opentelemetry/deployment/pom.xml index bb030a1ca3769..6642c020a48ef 100644 --- a/extensions/opentelemetry/deployment/pom.xml +++ b/extensions/opentelemetry/deployment/pom.xml @@ -86,6 +86,11 @@ vertx-web-client test + + io.quarkus + quarkus-reactive-routes-deployment + test + io.quarkus quarkus-resteasy-deployment diff --git a/extensions/opentelemetry/deployment/src/test/java/io/quarkus/opentelemetry/deployment/OpenTelemetryReactiveRoutesTest.java b/extensions/opentelemetry/deployment/src/test/java/io/quarkus/opentelemetry/deployment/OpenTelemetryReactiveRoutesTest.java new file mode 100644 index 0000000000000..e127973ea23cc --- /dev/null +++ b/extensions/opentelemetry/deployment/src/test/java/io/quarkus/opentelemetry/deployment/OpenTelemetryReactiveRoutesTest.java @@ -0,0 +1,95 @@ +package io.quarkus.opentelemetry.deployment; + +import static io.opentelemetry.api.trace.SpanKind.SERVER; +import static io.quarkus.opentelemetry.deployment.common.TestSpanExporter.getSpanByKindAndParentId; +import static io.quarkus.opentelemetry.deployment.common.TestUtil.assertStringAttribute; +import static org.hamcrest.Matchers.is; +import static org.junit.jupiter.api.Assertions.assertEquals; + +import java.util.List; + +import jakarta.enterprise.context.ApplicationScoped; +import jakarta.inject.Inject; +import jakarta.ws.rs.GET; + +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; + +import io.opentelemetry.sdk.trace.data.SpanData; +import io.opentelemetry.semconv.trace.attributes.SemanticAttributes; +import io.quarkus.opentelemetry.deployment.common.TestSpanExporter; +import io.quarkus.opentelemetry.deployment.common.TestSpanExporterProvider; +import io.quarkus.opentelemetry.deployment.common.TestUtil; +import io.quarkus.test.QuarkusUnitTest; +import io.quarkus.vertx.web.Route; +import io.restassured.RestAssured; +import io.vertx.ext.web.RoutingContext; + +public class OpenTelemetryReactiveRoutesTest { + @RegisterExtension + static final QuarkusUnitTest TEST = new QuarkusUnitTest().setArchiveProducer( + () -> ShrinkWrap.create(JavaArchive.class) + .addClass(TestUtil.class) + .addClass(TestSpanExporter.class) + .addClass(TestSpanExporterProvider.class) + .addAsResource("resource-config/application.properties", "application.properties") + .addAsResource( + "META-INF/services-config/io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider", + "META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider")); + @Inject + TestSpanExporter spanExporter; + + @AfterEach + void tearDown() { + spanExporter.reset(); + } + + @Test + void root() { + RestAssured.when() + .get("/").then() + .statusCode(200) + .body(is("hello")); + + List spans = spanExporter.getFinishedSpanItems(1); + + final SpanData server = getSpanByKindAndParentId(spans, SERVER, "0000000000000000"); + assertEquals("GET /", server.getName()); + assertStringAttribute(server, SemanticAttributes.HTTP_ROUTE, "/"); + } + + @Test + void nonRoot() { + RestAssured.when() + .get("/hello").then() + .statusCode(200) + .body(is("hello world")); + + List spans = spanExporter.getFinishedSpanItems(1); + + final SpanData server = getSpanByKindAndParentId(spans, SERVER, "0000000000000000"); + assertEquals("GET /hello", server.getName()); + assertStringAttribute(server, SemanticAttributes.HTTP_ROUTE, "/hello"); + } + + @ApplicationScoped + public static class Routes { + + @Route(path = "/", methods = Route.HttpMethod.GET) + public void root(RoutingContext rc) { + rc.response().end("hello"); + } + + @Route(path = "/hello", methods = Route.HttpMethod.GET) + public void hello(RoutingContext rc) { + String name = rc.request().getParam("name"); + if (name == null) { + name = "world"; + } + rc.response().end("hello " + name); + } + } +} diff --git a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/vertx/HttpInstrumenterVertxTracer.java b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/vertx/HttpInstrumenterVertxTracer.java index 254504abe1607..78e33ea8d8abf 100644 --- a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/vertx/HttpInstrumenterVertxTracer.java +++ b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/vertx/HttpInstrumenterVertxTracer.java @@ -156,7 +156,7 @@ public String get(final io.opentelemetry.context.Context context, final HttpRequ route = requestSpan.getContext().getLocal("VertxRoute"); } - if (route != null && route.length() > 1) { + if (route != null && route.length() >= 1) { return route; } diff --git a/integration-tests/opentelemetry/src/test/java/io/quarkus/it/opentelemetry/OpenTelemetryTest.java b/integration-tests/opentelemetry/src/test/java/io/quarkus/it/opentelemetry/OpenTelemetryTest.java index f830b94590efa..f88b3366885d4 100644 --- a/integration-tests/opentelemetry/src/test/java/io/quarkus/it/opentelemetry/OpenTelemetryTest.java +++ b/integration-tests/opentelemetry/src/test/java/io/quarkus/it/opentelemetry/OpenTelemetryTest.java @@ -15,7 +15,6 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; @@ -153,7 +152,7 @@ void testEmptyClientPath() { Map clientServer = getSpanByKindAndParentId(spans, SERVER, client.get("spanId")); assertEquals(SERVER.toString(), clientServer.get("kind")); verifyResource(clientServer); - assertEquals("GET", clientServer.get("name")); + assertEquals("GET /", clientServer.get("name")); assertEquals(SERVER.toString(), clientServer.get("kind")); assertTrue((Boolean) clientServer.get("ended")); assertTrue((Boolean) clientServer.get("parent_valid")); @@ -163,7 +162,7 @@ void testEmptyClientPath() { assertEquals(pathParamUrl.getHost(), server.get("attr_net.host.name")); assertEquals(pathParamUrl.getPort(), Integer.valueOf((String) server.get("attr_net.host.port"))); assertEquals("http", clientServer.get("attr_http.scheme")); - assertNull(clientServer.get("attr_http.route")); + assertEquals("/", clientServer.get("attr_http.route")); assertEquals("200", clientServer.get("attr_http.status_code")); assertNotNull(clientServer.get("attr_http.client_ip")); assertNotNull(clientServer.get("attr_user_agent.original")); @@ -219,7 +218,7 @@ void testSlashClientPath() { Map clientServer = getSpanByKindAndParentId(spans, SERVER, client.get("spanId")); assertEquals(SERVER.toString(), clientServer.get("kind")); verifyResource(clientServer); - assertEquals("GET", clientServer.get("name")); + assertEquals("GET /", clientServer.get("name")); assertEquals(SERVER.toString(), clientServer.get("kind")); assertTrue((Boolean) clientServer.get("ended")); assertTrue((Boolean) clientServer.get("parent_valid")); @@ -229,7 +228,7 @@ void testSlashClientPath() { assertEquals(pathParamUrl.getHost(), server.get("attr_net.host.name")); assertEquals(pathParamUrl.getPort(), Integer.valueOf((String) server.get("attr_net.host.port"))); assertEquals("http", clientServer.get("attr_http.scheme")); - assertNull(clientServer.get("attr_http.route")); + assertEquals("/", clientServer.get("attr_http.route")); assertEquals("200", clientServer.get("attr_http.status_code")); assertNotNull(clientServer.get("attr_http.client_ip")); assertNotNull(clientServer.get("attr_user_agent.original"));