diff --git a/integration-tests/opentelemetry/src/main/java/io/quarkus/it/opentelemetry/SimpleResource.java b/integration-tests/opentelemetry/src/main/java/io/quarkus/it/opentelemetry/SimpleResource.java index e31106f08b29a..088a66a943c29 100644 --- a/integration-tests/opentelemetry/src/main/java/io/quarkus/it/opentelemetry/SimpleResource.java +++ b/integration-tests/opentelemetry/src/main/java/io/quarkus/it/opentelemetry/SimpleResource.java @@ -10,6 +10,9 @@ import org.eclipse.microprofile.rest.client.inject.RegisterRestClient; import org.eclipse.microprofile.rest.client.inject.RestClient; +import io.opentelemetry.api.baggage.Baggage; +import io.opentelemetry.context.Scope; + @Path("") @Produces(MediaType.APPLICATION_JSON) public class SimpleResource { @@ -22,6 +25,10 @@ public interface SimpleClient { @Path("/") @GET TraceData slashPath(); + + @Path("/from-baggage") + @GET + TraceData fromBaggagePath(); } @Inject @@ -31,6 +38,9 @@ public interface SimpleClient { @RestClient SimpleClient simpleClient; + @Inject + Baggage baggage; + @GET public TraceData noPath() { TraceData data = new TraceData(); @@ -50,6 +60,25 @@ public TraceData slashPathClient() { return simpleClient.slashPath(); } + @GET + @Path("/slashpath-baggage") + public TraceData slashPathBaggageClient() { + try (Scope scope = baggage.toBuilder() + .put("baggage-key", "baggage-value") + .build() + .makeCurrent()) { + return simpleClient.fromBaggagePath(); + } + } + + @GET + @Path("/from-baggage") + public TraceData fromBaggageValue() { + TraceData data = new TraceData(); + data.message = baggage.getEntryValue("baggage-key"); + return data; + } + @GET @Path("/direct") public TraceData directTrace() { 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 f88b3366885d4..1e970fc6a583f 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 @@ -235,6 +235,43 @@ void testSlashClientPath() { assertEquals(clientServer.get("parentSpanId"), client.get("spanId")); } + @Test + void testBaggagePath() { + given() + .contentType("application/json") + .when().get("/slashpath-baggage") + .then() + .statusCode(200) + .body("message", equalTo("baggage-value")); + + await().atMost(5, SECONDS).until(() -> getSpans().size() == 3); + List> spans = getSpans(); + assertEquals(3, spans.size()); + assertEquals(1, spans.stream().map(map -> map.get("traceId")).collect(toSet()).size()); + + Map server = getSpanByKindAndParentId(spans, SERVER, "0000000000000000"); + assertEquals(SERVER.toString(), server.get("kind")); + verifyResource(server); + assertEquals("GET /slashpath-baggage", server.get("name")); + assertEquals(SpanId.getInvalid(), server.get("parent_spanId")); + assertEquals(TraceId.getInvalid(), server.get("parent_traceId")); + assertFalse((Boolean) server.get("parent_valid")); + assertFalse((Boolean) server.get("parent_remote")); + + Map client = getSpanByKindAndParentId(spans, CLIENT, server.get("spanId")); + assertEquals(CLIENT.toString(), client.get("kind")); + assertEquals("GET", client.get("name")); + assertEquals("http://localhost:8081/from-baggage", client.get("attr_http.url")); + assertEquals("200", client.get("attr_http.status_code")); + assertEquals(client.get("parentSpanId"), server.get("spanId")); + + Map clientServer = getSpanByKindAndParentId(spans, SERVER, client.get("spanId")); + assertEquals(SERVER.toString(), clientServer.get("kind")); + verifyResource(clientServer); + assertEquals("GET /from-baggage", clientServer.get("name")); + assertEquals(clientServer.get("parentSpanId"), client.get("spanId")); + } + @Test void testChainedResourceTracing() { given()