diff --git a/extensions/micrometer/runtime/src/main/java/io/quarkus/micrometer/runtime/binder/vertx/VertxHttpServerMetrics.java b/extensions/micrometer/runtime/src/main/java/io/quarkus/micrometer/runtime/binder/vertx/VertxHttpServerMetrics.java index ad5f535e4437c..51b2521508021 100644 --- a/extensions/micrometer/runtime/src/main/java/io/quarkus/micrometer/runtime/binder/vertx/VertxHttpServerMetrics.java +++ b/extensions/micrometer/runtime/src/main/java/io/quarkus/micrometer/runtime/binder/vertx/VertxHttpServerMetrics.java @@ -131,7 +131,7 @@ public HttpRequestMetric responsePushed(LongTaskTimer.Sample socketMetric, HttpM public void requestRouted(HttpRequestMetric requestMetric, String route) { // note that in the case of a route (e.g. /dev-ui/) mounted on a router (e.g. /q/) // this method will be called twice, once for the router (route=/q/), the second time for the route (route=/dev-ui/) - + log.debugf("requestRouted %s %s", route, requestMetric); if (route == null) { diff --git a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/vertx/MetricRequest.java b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/vertx/MetricRequest.java index f76c13d47ab32..c491ad30cd600 100644 --- a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/vertx/MetricRequest.java +++ b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/vertx/MetricRequest.java @@ -8,6 +8,7 @@ public final class MetricRequest { private final HttpRequest request; + private String currentRoutePath; MetricRequest(final HttpRequest request) { this.request = request; @@ -24,4 +25,37 @@ Optional getContext() { static MetricRequest request(final HttpRequest httpRequest) { return new MetricRequest(httpRequest); } + + void appendCurrentRoutePath(String path) { + // we append the path to the current route path + // if a router is mounted on /q/ for instance, and a route of this router on /dev-ui/ + // a request to /q/dev-ui/ needs to be affected to the /q/dev-ui/ path + // appendCurrentRoutePath() will be called twice, once with /q/ and the second time with /dev-ui/ + if (path == null || path.isEmpty()) { + return; + } + + if (this.currentRoutePath == null) { + this.currentRoutePath = path; + return; + } + + boolean currentRoutePathTrailingSlash = this.currentRoutePath.endsWith("/"); + boolean pathLeadingSlash = path.startsWith("/"); + if (currentRoutePathTrailingSlash) { + if (pathLeadingSlash) { + this.currentRoutePath = this.currentRoutePath + path.substring(1); + } else { + this.currentRoutePath = this.currentRoutePath + path; + } + } else if (pathLeadingSlash) { + this.currentRoutePath = this.currentRoutePath + path; + } else { + this.currentRoutePath = this.currentRoutePath + '/' + path; + } + } + + String getCurrentRoutePath() { + return currentRoutePath; + } } diff --git a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/vertx/OpenTelemetryVertxHttpMetricsFactory.java b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/vertx/OpenTelemetryVertxHttpMetricsFactory.java index 756a6fc807cf5..a24b1ed485cb8 100644 --- a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/vertx/OpenTelemetryVertxHttpMetricsFactory.java +++ b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/vertx/OpenTelemetryVertxHttpMetricsFactory.java @@ -42,9 +42,15 @@ public MetricRequest requestBegin(final Object socketMetric, final HttpRequest r @Override public void requestRouted(final MetricRequest requestMetric, final String route) { - if (route != null) { - requestMetric.getContext().ifPresent(context -> context.putLocal("VertxRoute", route)); + // note that in the case of a route (e.g. /dev-ui/) mounted on a router (e.g. /q/) + // this method will be called twice, once for the router (route=/q/), the second time for the route (route=/dev-ui/) + if (route == null) { + return; } + + requestMetric.appendCurrentRoutePath(route); + requestMetric.getContext() + .ifPresent(context -> context.putLocal("VertxRoute", requestMetric.getCurrentRoutePath())); } @Override diff --git a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/vertx/OpenTelemetryVertxMetricsFactory.java b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/vertx/OpenTelemetryVertxMetricsFactory.java index 6d030c609b780..4f0fb481f4f9a 100644 --- a/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/vertx/OpenTelemetryVertxMetricsFactory.java +++ b/extensions/opentelemetry/runtime/src/main/java/io/quarkus/opentelemetry/runtime/tracing/intrumentation/vertx/OpenTelemetryVertxMetricsFactory.java @@ -39,9 +39,15 @@ public MetricRequest requestBegin(final Object socketMetric, final HttpRequest r @Override public void requestRouted(final MetricRequest requestMetric, final String route) { - if (route != null) { - requestMetric.getContext().ifPresent(context -> context.putLocal("VertxRoute", route)); + // note that in the case of a route (e.g. /dev-ui/) mounted on a router (e.g. /q/) + // this method will be called twice, once for the router (route=/q/), the second time for the route (route=/dev-ui/) + if (route == null) { + return; } + + requestMetric.appendCurrentRoutePath(route); + requestMetric.getContext() + .ifPresent(context -> context.putLocal("VertxRoute", requestMetric.getCurrentRoutePath())); } } }