forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix http.route tracing attribute reporting
We know properly report the root path whereas previously it was being ignored Fixes: quarkusio#34778 (cherry picked from commit aa2a35a)
- Loading branch information
Showing
4 changed files
with
105 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
...nt/src/test/java/io/quarkus/opentelemetry/deployment/OpenTelemetryReactiveRoutesTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<SpanData> 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<SpanData> 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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters