Skip to content

Commit f35b854

Browse files
brunobatgeoand
authored andcommitted
test for WithSpan on a rest client
1 parent 1070e3b commit f35b854

File tree

2 files changed

+86
-0
lines changed

2 files changed

+86
-0
lines changed

integration-tests/opentelemetry/src/main/java/io/quarkus/it/opentelemetry/PingPongResource.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
import org.eclipse.microprofile.rest.client.inject.RegisterRestClient;
1111
import org.eclipse.microprofile.rest.client.inject.RestClient;
1212

13+
import io.opentelemetry.instrumentation.annotations.SpanAttribute;
14+
import io.opentelemetry.instrumentation.annotations.WithSpan;
1315
import io.smallrye.common.annotation.Blocking;
1416
import io.smallrye.mutiny.Uni;
1517
import io.vertx.core.MultiMap;
@@ -34,6 +36,11 @@ public interface PingPongRestClient {
3436
@GET
3537
@Path("/client/pong/{message}")
3638
Uni<String> asyncPingpong(@PathParam("message") String message);
39+
40+
@GET
41+
@Path("/client/pong/{message}")
42+
@WithSpan
43+
String pingpongIntercept(@SpanAttribute(value = "message") @PathParam("message") String message);
3744
}
3845

3946
@Inject
@@ -81,4 +88,9 @@ public Uni<String> asyncPingNamed(@PathParam("message") String message) {
8188
.onItemOrFailure().call(httpClient::close);
8289
}
8390

91+
@GET
92+
@Path("pong-intercept/{message}")
93+
public String pongIntercept(@PathParam("message") String message) {
94+
return pingRestClient.pingpongIntercept(message);
95+
}
8496
}

integration-tests/opentelemetry/src/test/java/io/quarkus/it/opentelemetry/OpenTelemetryTest.java

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import static org.junit.jupiter.api.Assertions.assertEquals;
1616
import static org.junit.jupiter.api.Assertions.assertFalse;
1717
import static org.junit.jupiter.api.Assertions.assertNotNull;
18+
import static org.junit.jupiter.api.Assertions.assertNull;
1819
import static org.junit.jupiter.api.Assertions.assertTrue;
1920
import static org.junit.jupiter.api.Assertions.fail;
2021

@@ -557,6 +558,79 @@ void testAsyncClientTracing() {
557558
assertNotNull(clientServer.get("attr_user_agent.original"));
558559
}
559560

561+
@Test
562+
void testClientTracingWithInterceptor() {
563+
given()
564+
.when().get("/client/pong-intercept/one")
565+
.then()
566+
.statusCode(200)
567+
.body(containsString("one"));
568+
569+
await().atMost(5, SECONDS).until(() -> getSpans().size() == 4);
570+
List<Map<String, Object>> spans = getSpans();
571+
assertEquals(4, spans.size());
572+
assertEquals(1, spans.stream().map(map -> map.get("traceId")).collect(toSet()).size());
573+
574+
Map<String, Object> server = getSpanByKindAndParentId(spans, SERVER, "0000000000000000");
575+
assertEquals(SERVER.toString(), server.get("kind"));
576+
verifyResource(server);
577+
assertEquals("GET /client/pong-intercept/{message}", server.get("name"));
578+
assertEquals(SERVER.toString(), server.get("kind"));
579+
assertTrue((Boolean) server.get("ended"));
580+
assertEquals(SpanId.getInvalid(), server.get("parent_spanId"));
581+
assertEquals(TraceId.getInvalid(), server.get("parent_traceId"));
582+
assertFalse((Boolean) server.get("parent_valid"));
583+
assertFalse((Boolean) server.get("parent_remote"));
584+
assertEquals("GET", server.get("attr_http.method"));
585+
assertEquals("/client/pong-intercept/one", server.get("attr_http.target"));
586+
assertEquals(pathParamUrl.getHost(), server.get("attr_net.host.name"));
587+
assertEquals(pathParamUrl.getPort(), Integer.valueOf((String) server.get("attr_net.host.port")));
588+
assertEquals("http", server.get("attr_http.scheme"));
589+
assertEquals("/client/pong-intercept/{message}", server.get("attr_http.route"));
590+
assertEquals("200", server.get("attr_http.status_code"));
591+
assertNotNull(server.get("attr_http.client_ip"));
592+
assertNotNull(server.get("attr_user_agent.original"));
593+
594+
Map<String, Object> fromInterceptor = getSpanByKindAndParentId(spans, INTERNAL, server.get("spanId"));
595+
assertEquals("PingPongRestClient.pingpongIntercept", fromInterceptor.get("name"));
596+
assertEquals(INTERNAL.toString(), fromInterceptor.get("kind"));
597+
assertTrue((Boolean) fromInterceptor.get("ended"));
598+
assertTrue((Boolean) fromInterceptor.get("parent_valid"));
599+
assertFalse((Boolean) fromInterceptor.get("parent_remote"));
600+
assertNull(fromInterceptor.get("attr_http.method"));
601+
assertNull(fromInterceptor.get("attr_http.status_code"));
602+
assertEquals("one", fromInterceptor.get("attr_message"));
603+
604+
Map<String, Object> client = getSpanByKindAndParentId(spans, CLIENT, fromInterceptor.get("spanId"));
605+
assertEquals("GET", client.get("name"));
606+
assertEquals(SpanKind.CLIENT.toString(), client.get("kind"));
607+
assertTrue((Boolean) client.get("ended"));
608+
assertTrue((Boolean) client.get("parent_valid"));
609+
assertFalse((Boolean) client.get("parent_remote"));
610+
assertEquals("GET", client.get("attr_http.method"));
611+
assertEquals("http://localhost:8081/client/pong/one", client.get("attr_http.url"));
612+
assertEquals("200", client.get("attr_http.status_code"));
613+
614+
Map<String, Object> clientServer = getSpanByKindAndParentId(spans, SERVER, client.get("spanId"));
615+
assertEquals(SERVER.toString(), clientServer.get("kind"));
616+
verifyResource(clientServer);
617+
assertEquals("GET /client/pong/{message}", clientServer.get("name"));
618+
assertEquals(SERVER.toString(), clientServer.get("kind"));
619+
assertTrue((Boolean) clientServer.get("ended"));
620+
assertTrue((Boolean) clientServer.get("parent_valid"));
621+
assertTrue((Boolean) clientServer.get("parent_remote"));
622+
assertEquals("GET", clientServer.get("attr_http.method"));
623+
assertEquals("/client/pong/one", clientServer.get("attr_http.target"));
624+
assertEquals(pathParamUrl.getHost(), server.get("attr_net.host.name"));
625+
assertEquals(pathParamUrl.getPort(), Integer.valueOf((String) server.get("attr_net.host.port")));
626+
assertEquals("http", clientServer.get("attr_http.scheme"));
627+
assertEquals("/client/pong/{message}", clientServer.get("attr_http.route"));
628+
assertEquals("200", clientServer.get("attr_http.status_code"));
629+
assertNotNull(clientServer.get("attr_http.client_ip"));
630+
assertNotNull(clientServer.get("attr_user_agent.original"));
631+
assertEquals(clientServer.get("parentSpanId"), client.get("spanId"));
632+
}
633+
560634
@Test
561635
void testTemplatedPathOnClass() {
562636
given()

0 commit comments

Comments
 (0)