Skip to content

Commit

Permalink
Tracing: more eventbus and HTTP tags (#5024)
Browse files Browse the repository at this point in the history
* emit tags suitable for OpenTelemetry 1.18 Semantic Conventions

* Tag names updates

- In Vert.x 4, use OpenTracing prefixes
- Take latest OTel spec into account https://opentelemetry.io/docs/specs/semconv/http/http-spans

Signed-off-by: Thomas Segismont <tsegismont@gmail.com>

---------

Signed-off-by: Thomas Segismont <tsegismont@gmail.com>
Co-authored-by: Olamide Kolawole <olamshin@gmail.com>
  • Loading branch information
tsegismont and Olamide Kolawole authored Dec 11, 2023
1 parent cb6dd95 commit 3f3a6b2
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 11 deletions.
20 changes: 15 additions & 5 deletions src/main/java/io/vertx/core/eventbus/impl/MessageTagExtractor.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,31 @@ private MessageTagExtractor() {

@Override
public int len(Message<?> obj) {
return 1;
return 3;
}

@Override
public String name(Message<?> obj, int index) {
if (index == 0) {
return "message_bus.destination";
switch (index) {
case 0:
return "message_bus.destination";
case 1:
return "message_bus.system";
case 2:
return "message_bus.operation";
}
throw new IndexOutOfBoundsException("Invalid tag index " + index);
}

@Override
public String value(Message<?> obj, int index) {
if (index == 0) {
return obj.address();
switch (index) {
case 0:
return obj.address();
case 1:
return "vertx-eventbus";
case 2:
return "publish";
}
throw new IndexOutOfBoundsException("Invalid tag index " + index);
}
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/io/vertx/core/http/impl/HttpUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public final class HttpUtils {
static final TagExtractor<HttpServerRequest> SERVER_REQUEST_TAG_EXTRACTOR = new TagExtractor<HttpServerRequest>() {
@Override
public int len(HttpServerRequest req) {
return 2;
return req.query() == null ? 4 : 5;
}
@Override
public String name(HttpServerRequest req, int index) {
Expand All @@ -79,6 +79,12 @@ public String name(HttpServerRequest req, int index) {
return "http.url";
case 1:
return "http.method";
case 2:
return "http.scheme";
case 3:
return "http.path";
case 4:
return "http.query";
}
throw new IndexOutOfBoundsException("Invalid tag index " + index);
}
Expand All @@ -89,6 +95,12 @@ public String value(HttpServerRequest req, int index) {
return req.absoluteURI();
case 1:
return req.method().name();
case 2:
return req.scheme();
case 3:
return req.path();
case 4:
return req.query();
}
throw new IndexOutOfBoundsException("Invalid tag index " + index);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import io.vertx.core.Vertx;
import io.vertx.core.eventbus.DeliveryOptions;
import io.vertx.core.tracing.TracingPolicy;
import io.vertx.test.core.Repeat;
import io.vertx.test.core.VertxTestBase;
import io.vertx.test.faketracer.FakeTracer;
import io.vertx.test.faketracer.Span;
Expand Down Expand Up @@ -164,6 +163,8 @@ private void testRequestReply(TracingPolicy policy, boolean create, boolean fail
assertSingleTrace(finishedSpans);
finishedSpans.forEach(span -> {
assertEquals("send", span.operation);
assertEquals("vertx-eventbus", span.getTags().get("message_bus.system"));
assertEquals("publish", span.getTags().get("message_bus.operation"));
});
}

Expand Down
12 changes: 8 additions & 4 deletions src/test/java/io/vertx/core/spi/tracing/HttpTracingTestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@
package io.vertx.core.spi.tracing;

import io.vertx.core.Context;
import io.vertx.core.http.*;
import io.vertx.test.faketracer.Span;
import io.vertx.core.http.HttpMethod;
import io.vertx.core.http.HttpTestBase;
import io.vertx.test.faketracer.FakeTracer;
import io.vertx.test.faketracer.Span;
import org.junit.Test;

import java.util.List;
Expand Down Expand Up @@ -108,7 +109,7 @@ public void testMultipleHttpServerRequest() throws Exception {
switch (serverReq.path()) {
case "/1": {
vertx.setTimer(10, id -> {
client.request(HttpMethod.GET, 8080, "localhost", "/2", onSuccess(clientReq -> {
client.request(HttpMethod.GET, 8080, "localhost", "/2?q=true", onSuccess(clientReq -> {
clientReq.send(onSuccess(resp -> {
serverReq.response().end();
}));
Expand Down Expand Up @@ -156,9 +157,12 @@ public void testMultipleHttpServerRequest() throws Exception {

String scheme = createBaseServerOptions().isSsl() ? "https" : "http";
for (Span server2Span: lastServerSpans) {
assertEquals(scheme, server2Span.getTags().get("http.scheme"));
assertEquals("/2", server2Span.getTags().get("http.path"));
assertEquals("q=true", server2Span.getTags().get("http.query"));
Span client2Span = spanMap.get(server2Span.parentId);
assertEquals("GET", client2Span.operation);
assertEquals(scheme + "://localhost:8080/2", client2Span.getTags().get("http.url"));
assertEquals(scheme + "://localhost:8080/2?q=true", client2Span.getTags().get("http.url"));
assertEquals("200", client2Span.getTags().get("http.status_code"));
assertEquals("client", client2Span.getTags().get("span_kind"));
Span server1Span = spanMap.get(client2Span.parentId);
Expand Down

0 comments on commit 3f3a6b2

Please sign in to comment.