Skip to content

Commit

Permalink
Merge pull request quarkusio#18074 from kenfinnigan/fix-otel-tests
Browse files Browse the repository at this point in the history
Adjust OpenTelemetry integration test to handle out of order spans
  • Loading branch information
kenfinnigan authored Jun 22, 2021
2 parents d25474b + 60a30b7 commit b22d7f7
Showing 1 changed file with 196 additions and 154 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -266,84 +266,105 @@ void testClientTracing() {

Awaitility.await().atMost(Duration.ofMinutes(2)).until(() -> getSpans().size() == 3);

List<Map<String, Object>> spans = getSpans();

// Server Span
Map<String, Object> spanData = spans.get(2);
Assertions.assertNotNull(spanData);
Assertions.assertNotNull(spanData.get("spanId"));

String parentSpanId = (String) spanData.get("spanId");
String parentTraceId = (String) spanData.get("traceId");

verifyResource(spanData);

Assertions.assertEquals("client/ping/{message}", spanData.get("name"));
Assertions.assertEquals(SpanKind.SERVER.toString(), spanData.get("kind"));
Assertions.assertTrue((Boolean) spanData.get("ended"));

Assertions.assertEquals(SpanId.getInvalid(), spanData.get("parent_spanId"));
Assertions.assertEquals(TraceId.getInvalid(), spanData.get("parent_traceId"));
Assertions.assertFalse((Boolean) spanData.get("parent_valid"));
Assertions.assertFalse((Boolean) spanData.get("parent_remote"));

Assertions.assertEquals("GET", spanData.get("attr_http.method"));
Assertions.assertEquals("1.1", spanData.get("attr_http.flavor"));
Assertions.assertEquals("/client/ping/one", spanData.get("attr_http.target"));
Assertions.assertEquals(pathParamUrl.getAuthority(), spanData.get("attr_http.host"));
Assertions.assertEquals("http", spanData.get("attr_http.scheme"));
Assertions.assertEquals("/client/ping/{message}", spanData.get("attr_http.route"));
Assertions.assertEquals("200", spanData.get("attr_http.status_code"));
Assertions.assertNotNull(spanData.get("attr_http.client_ip"));
Assertions.assertNotNull(spanData.get("attr_http.user_agent"));

// Client span
spanData = spans.get(1);
Assertions.assertNotNull(spanData);
Assertions.assertNotNull(spanData.get("spanId"));

verifyResource(spanData);

Assertions.assertEquals("client/pong/{message}", spanData.get("name"));
Assertions.assertEquals(SpanKind.CLIENT.toString(), spanData.get("kind"));
Assertions.assertTrue((Boolean) spanData.get("ended"));

Assertions.assertEquals(parentSpanId, spanData.get("parent_spanId"));
Assertions.assertEquals(parentTraceId, spanData.get("parent_traceId"));
Assertions.assertTrue((Boolean) spanData.get("parent_valid"));
Assertions.assertFalse((Boolean) spanData.get("parent_remote"));

Assertions.assertEquals("GET", spanData.get("attr_http.method"));
Assertions.assertEquals("http://localhost:8081/client/pong/one", spanData.get("attr_http.url"));
Assertions.assertEquals("200", spanData.get("attr_http.status_code"));

parentSpanId = (String) spanData.get("spanId");

// Server span of client
spanData = spans.get(0);
Assertions.assertNotNull(spanData);
Assertions.assertNotNull(spanData.get("spanId"));

verifyResource(spanData);

Assertions.assertEquals("client/pong/{message}", spanData.get("name"));
Assertions.assertEquals(SpanKind.SERVER.toString(), spanData.get("kind"));
Assertions.assertTrue((Boolean) spanData.get("ended"));

Assertions.assertEquals(parentSpanId, spanData.get("parent_spanId"));
Assertions.assertEquals(parentTraceId, spanData.get("parent_traceId"));
Assertions.assertTrue((Boolean) spanData.get("parent_valid"));
Assertions.assertTrue((Boolean) spanData.get("parent_remote"));
boolean outsideServerFound = false;
boolean clientFound = false;
boolean clientServerFound = false;

String serverSpanId = null;
String serverTraceId = null;
String clientSpanId = null;

for (Map<String, Object> spanData : getSpans()) {
Assertions.assertNotNull(spanData);
Assertions.assertNotNull(spanData.get("spanId"));

if (spanData.get("kind").equals(SpanKind.SERVER.toString())
&& spanData.get("name").equals("client/ping/{message}")) {
outsideServerFound = true;
// Server Span
serverSpanId = (String) spanData.get("spanId");
serverTraceId = (String) spanData.get("traceId");

verifyResource(spanData);

Assertions.assertEquals("client/ping/{message}", spanData.get("name"));
Assertions.assertEquals(SpanKind.SERVER.toString(), spanData.get("kind"));
Assertions.assertTrue((Boolean) spanData.get("ended"));

Assertions.assertEquals(SpanId.getInvalid(), spanData.get("parent_spanId"));
Assertions.assertEquals(TraceId.getInvalid(), spanData.get("parent_traceId"));
Assertions.assertFalse((Boolean) spanData.get("parent_valid"));
Assertions.assertFalse((Boolean) spanData.get("parent_remote"));

Assertions.assertEquals("GET", spanData.get("attr_http.method"));
Assertions.assertEquals("1.1", spanData.get("attr_http.flavor"));
Assertions.assertEquals("/client/ping/one", spanData.get("attr_http.target"));
Assertions.assertEquals(pathParamUrl.getAuthority(), spanData.get("attr_http.host"));
Assertions.assertEquals("http", spanData.get("attr_http.scheme"));
Assertions.assertEquals("/client/ping/{message}", spanData.get("attr_http.route"));
Assertions.assertEquals("200", spanData.get("attr_http.status_code"));
Assertions.assertNotNull(spanData.get("attr_http.client_ip"));
Assertions.assertNotNull(spanData.get("attr_http.user_agent"));
} else if (spanData.get("kind").equals(SpanKind.CLIENT.toString())
&& spanData.get("name").equals("client/pong/{message}")) {
clientFound = true;
// Client span
verifyResource(spanData);

Assertions.assertEquals("client/pong/{message}", spanData.get("name"));
Assertions.assertEquals(SpanKind.CLIENT.toString(), spanData.get("kind"));
Assertions.assertTrue((Boolean) spanData.get("ended"));

if (serverSpanId != null) {
Assertions.assertEquals(serverSpanId, spanData.get("parent_spanId"));
}
if (serverTraceId != null) {
Assertions.assertEquals(serverTraceId, spanData.get("parent_traceId"));
}
Assertions.assertTrue((Boolean) spanData.get("parent_valid"));
Assertions.assertFalse((Boolean) spanData.get("parent_remote"));

Assertions.assertEquals("GET", spanData.get("attr_http.method"));
Assertions.assertEquals("http://localhost:8081/client/pong/one", spanData.get("attr_http.url"));
Assertions.assertEquals("200", spanData.get("attr_http.status_code"));

clientSpanId = (String) spanData.get("spanId");
} else if (spanData.get("kind").equals(SpanKind.SERVER.toString())
&& spanData.get("name").equals("client/pong/{message}")) {
clientServerFound = true;
// Server span of client
verifyResource(spanData);

Assertions.assertEquals("client/pong/{message}", spanData.get("name"));
Assertions.assertEquals(SpanKind.SERVER.toString(), spanData.get("kind"));
Assertions.assertTrue((Boolean) spanData.get("ended"));

if (clientSpanId != null) {
Assertions.assertEquals(clientSpanId, spanData.get("parent_spanId"));
}
if (serverTraceId != null) {
Assertions.assertEquals(serverTraceId, spanData.get("parent_traceId"));
}
Assertions.assertTrue((Boolean) spanData.get("parent_valid"));
Assertions.assertTrue((Boolean) spanData.get("parent_remote"));

Assertions.assertEquals("GET", spanData.get("attr_http.method"));
Assertions.assertEquals("1.1", spanData.get("attr_http.flavor"));
Assertions.assertEquals("/client/pong/one", spanData.get("attr_http.target"));
Assertions.assertEquals(pathParamUrl.getAuthority(), spanData.get("attr_http.host"));
Assertions.assertEquals("http", spanData.get("attr_http.scheme"));
Assertions.assertEquals("/client/pong/{message}", spanData.get("attr_http.route"));
Assertions.assertEquals("200", spanData.get("attr_http.status_code"));
Assertions.assertNotNull(spanData.get("attr_http.client_ip"));
Assertions.assertNotNull(spanData.get("attr_http.user_agent"));
} else {
Assertions.fail("Received an unknown Span - " + spanData.get("name"));
}
}

Assertions.assertEquals("GET", spanData.get("attr_http.method"));
Assertions.assertEquals("1.1", spanData.get("attr_http.flavor"));
Assertions.assertEquals("/client/pong/one", spanData.get("attr_http.target"));
Assertions.assertEquals(pathParamUrl.getAuthority(), spanData.get("attr_http.host"));
Assertions.assertEquals("http", spanData.get("attr_http.scheme"));
Assertions.assertEquals("/client/pong/{message}", spanData.get("attr_http.route"));
Assertions.assertEquals("200", spanData.get("attr_http.status_code"));
Assertions.assertNotNull(spanData.get("attr_http.client_ip"));
Assertions.assertNotNull(spanData.get("attr_http.user_agent"));
Assertions.assertTrue(outsideServerFound);
Assertions.assertTrue(clientFound);
Assertions.assertTrue(clientServerFound);
}

@Test
Expand All @@ -358,84 +379,105 @@ void testAsyncClientTracing() {

Awaitility.await().atMost(Duration.ofMinutes(2)).until(() -> getSpans().size() == 3);

List<Map<String, Object>> spans = getSpans();

// Server Span
Map<String, Object> spanData = spans.get(2);
Assertions.assertNotNull(spanData);
Assertions.assertNotNull(spanData.get("spanId"));

String parentSpanId = (String) spanData.get("spanId");
String parentTraceId = (String) spanData.get("traceId");

verifyResource(spanData);

Assertions.assertEquals("client/async-ping/{message}", spanData.get("name"));
Assertions.assertEquals(SpanKind.SERVER.toString(), spanData.get("kind"));
Assertions.assertTrue((Boolean) spanData.get("ended"));

Assertions.assertEquals(SpanId.getInvalid(), spanData.get("parent_spanId"));
Assertions.assertEquals(TraceId.getInvalid(), spanData.get("parent_traceId"));
Assertions.assertFalse((Boolean) spanData.get("parent_valid"));
Assertions.assertFalse((Boolean) spanData.get("parent_remote"));

Assertions.assertEquals("GET", spanData.get("attr_http.method"));
Assertions.assertEquals("1.1", spanData.get("attr_http.flavor"));
Assertions.assertEquals("/client/async-ping/one", spanData.get("attr_http.target"));
Assertions.assertEquals(pathParamUrl.getAuthority(), spanData.get("attr_http.host"));
Assertions.assertEquals("http", spanData.get("attr_http.scheme"));
Assertions.assertEquals("/client/async-ping/{message}", spanData.get("attr_http.route"));
Assertions.assertEquals("200", spanData.get("attr_http.status_code"));
Assertions.assertNotNull(spanData.get("attr_http.client_ip"));
Assertions.assertNotNull(spanData.get("attr_http.user_agent"));

// Client span
spanData = spans.get(1);
Assertions.assertNotNull(spanData);
Assertions.assertNotNull(spanData.get("spanId"));

verifyResource(spanData);

Assertions.assertEquals("client/pong/{message}", spanData.get("name"));
Assertions.assertEquals(SpanKind.CLIENT.toString(), spanData.get("kind"));
Assertions.assertTrue((Boolean) spanData.get("ended"));

Assertions.assertEquals(parentSpanId, spanData.get("parent_spanId"));
Assertions.assertEquals(parentTraceId, spanData.get("parent_traceId"));
Assertions.assertTrue((Boolean) spanData.get("parent_valid"));
Assertions.assertFalse((Boolean) spanData.get("parent_remote"));

Assertions.assertEquals("GET", spanData.get("attr_http.method"));
Assertions.assertEquals("http://localhost:8081/client/pong/one", spanData.get("attr_http.url"));
Assertions.assertEquals("200", spanData.get("attr_http.status_code"));

parentSpanId = (String) spanData.get("spanId");

// Server span of client
spanData = spans.get(0);
Assertions.assertNotNull(spanData);
Assertions.assertNotNull(spanData.get("spanId"));

verifyResource(spanData);

Assertions.assertEquals("client/pong/{message}", spanData.get("name"));
Assertions.assertEquals(SpanKind.SERVER.toString(), spanData.get("kind"));
Assertions.assertTrue((Boolean) spanData.get("ended"));

Assertions.assertEquals(parentSpanId, spanData.get("parent_spanId"));
Assertions.assertEquals(parentTraceId, spanData.get("parent_traceId"));
Assertions.assertTrue((Boolean) spanData.get("parent_valid"));
Assertions.assertTrue((Boolean) spanData.get("parent_remote"));
boolean outsideServerFound = false;
boolean clientFound = false;
boolean clientServerFound = false;

String serverSpanId = null;
String serverTraceId = null;
String clientSpanId = null;

for (Map<String, Object> spanData : getSpans()) {
Assertions.assertNotNull(spanData);
Assertions.assertNotNull(spanData.get("spanId"));

if (spanData.get("kind").equals(SpanKind.SERVER.toString())
&& spanData.get("name").equals("client/async-ping/{message}")) {
outsideServerFound = true;
// Server Span
serverSpanId = (String) spanData.get("spanId");
serverTraceId = (String) spanData.get("traceId");

verifyResource(spanData);

Assertions.assertEquals("client/async-ping/{message}", spanData.get("name"));
Assertions.assertEquals(SpanKind.SERVER.toString(), spanData.get("kind"));
Assertions.assertTrue((Boolean) spanData.get("ended"));

Assertions.assertEquals(SpanId.getInvalid(), spanData.get("parent_spanId"));
Assertions.assertEquals(TraceId.getInvalid(), spanData.get("parent_traceId"));
Assertions.assertFalse((Boolean) spanData.get("parent_valid"));
Assertions.assertFalse((Boolean) spanData.get("parent_remote"));

Assertions.assertEquals("GET", spanData.get("attr_http.method"));
Assertions.assertEquals("1.1", spanData.get("attr_http.flavor"));
Assertions.assertEquals("/client/async-ping/one", spanData.get("attr_http.target"));
Assertions.assertEquals(pathParamUrl.getAuthority(), spanData.get("attr_http.host"));
Assertions.assertEquals("http", spanData.get("attr_http.scheme"));
Assertions.assertEquals("/client/async-ping/{message}", spanData.get("attr_http.route"));
Assertions.assertEquals("200", spanData.get("attr_http.status_code"));
Assertions.assertNotNull(spanData.get("attr_http.client_ip"));
Assertions.assertNotNull(spanData.get("attr_http.user_agent"));
} else if (spanData.get("kind").equals(SpanKind.CLIENT.toString())
&& spanData.get("name").equals("client/pong/{message}")) {
clientFound = true;
// Client span
verifyResource(spanData);

Assertions.assertEquals("client/pong/{message}", spanData.get("name"));
Assertions.assertEquals(SpanKind.CLIENT.toString(), spanData.get("kind"));
Assertions.assertTrue((Boolean) spanData.get("ended"));

if (serverSpanId != null) {
Assertions.assertEquals(serverSpanId, spanData.get("parent_spanId"));
}
if (serverTraceId != null) {
Assertions.assertEquals(serverTraceId, spanData.get("parent_traceId"));
}
Assertions.assertTrue((Boolean) spanData.get("parent_valid"));
Assertions.assertFalse((Boolean) spanData.get("parent_remote"));

Assertions.assertEquals("GET", spanData.get("attr_http.method"));
Assertions.assertEquals("http://localhost:8081/client/pong/one", spanData.get("attr_http.url"));
Assertions.assertEquals("200", spanData.get("attr_http.status_code"));

clientSpanId = (String) spanData.get("spanId");
} else if (spanData.get("kind").equals(SpanKind.SERVER.toString())
&& spanData.get("name").equals("client/pong/{message}")) {
clientServerFound = true;
// Server span of client
verifyResource(spanData);

Assertions.assertEquals("client/pong/{message}", spanData.get("name"));
Assertions.assertEquals(SpanKind.SERVER.toString(), spanData.get("kind"));
Assertions.assertTrue((Boolean) spanData.get("ended"));

if (clientSpanId != null) {
Assertions.assertEquals(clientSpanId, spanData.get("parent_spanId"));
}
if (serverTraceId != null) {
Assertions.assertEquals(serverTraceId, spanData.get("parent_traceId"));
}
Assertions.assertTrue((Boolean) spanData.get("parent_valid"));
Assertions.assertTrue((Boolean) spanData.get("parent_remote"));

Assertions.assertEquals("GET", spanData.get("attr_http.method"));
Assertions.assertEquals("1.1", spanData.get("attr_http.flavor"));
Assertions.assertEquals("/client/pong/one", spanData.get("attr_http.target"));
Assertions.assertEquals(pathParamUrl.getAuthority(), spanData.get("attr_http.host"));
Assertions.assertEquals("http", spanData.get("attr_http.scheme"));
Assertions.assertEquals("/client/pong/{message}", spanData.get("attr_http.route"));
Assertions.assertEquals("200", spanData.get("attr_http.status_code"));
Assertions.assertNotNull(spanData.get("attr_http.client_ip"));
Assertions.assertNotNull(spanData.get("attr_http.user_agent"));
} else {
Assertions.fail("Received an unknown Span - " + spanData.get("name"));
}
}

Assertions.assertEquals("GET", spanData.get("attr_http.method"));
Assertions.assertEquals("1.1", spanData.get("attr_http.flavor"));
Assertions.assertEquals("/client/pong/one", spanData.get("attr_http.target"));
Assertions.assertEquals(pathParamUrl.getAuthority(), spanData.get("attr_http.host"));
Assertions.assertEquals("http", spanData.get("attr_http.scheme"));
Assertions.assertEquals("/client/pong/{message}", spanData.get("attr_http.route"));
Assertions.assertEquals("200", spanData.get("attr_http.status_code"));
Assertions.assertNotNull(spanData.get("attr_http.client_ip"));
Assertions.assertNotNull(spanData.get("attr_http.user_agent"));
Assertions.assertTrue(outsideServerFound);
Assertions.assertTrue(clientFound);
Assertions.assertTrue(clientServerFound);
}

private void verifyResource(Map<String, Object> spanData) {
Expand Down

0 comments on commit b22d7f7

Please sign in to comment.