|
@@ -5,8 +5,12 @@
|
|
|
|
|
|
package io.opentelemetry.javaagent.instrumentation.vertx;
|
|
|
|
|
|
+import static io.opentelemetry.context.ContextKey.named;
|
|
|
+
|
|
|
import io.opentelemetry.api.trace.Span;
|
|
|
import io.opentelemetry.context.Context;
|
|
|
+import io.opentelemetry.context.ContextKey;
|
|
|
+import io.opentelemetry.context.Scope;
|
|
|
import io.opentelemetry.instrumentation.api.instrumenter.LocalRootSpan;
|
|
|
import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRoute;
|
|
|
import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRouteSource;
|
|
@@ -20,6 +24,8 @@ import java.util.concurrent.ExecutionException;
|
|
|
/** This is used to wrap Vert.x Handlers to provide nice user-friendly SERVER span names */
|
|
|
public final class RoutingContextHandlerWrapper implements Handler<RoutingContext> {
|
|
|
|
|
|
+ private static final ContextKey<String> ROUTE_KEY = named("opentelemetry-vertx-route");
|
|
|
+
|
|
|
private final Handler<RoutingContext> handler;
|
|
|
|
|
|
public RoutingContextHandlerWrapper(Handler<RoutingContext> handler) {
|
|
@@ -29,13 +35,13 @@ public final class RoutingContextHandlerWrapper implements Handler<RoutingContex
|
|
|
@Override
|
|
|
public void handle(RoutingContext context) {
|
|
|
Context otelContext = Context.current();
|
|
|
- HttpServerRoute.update(
|
|
|
- otelContext,
|
|
|
- HttpServerRouteSource.CONTROLLER,
|
|
|
- RoutingContextHandlerWrapper::getRoute,
|
|
|
- context);
|
|
|
+ String route = getRoute(otelContext, context);
|
|
|
+ if (route != null && route.endsWith("/")) {
|
|
|
+ route = route.substring(0, route.length() - 1);
|
|
|
+ }
|
|
|
+ HttpServerRoute.update(otelContext, HttpServerRouteSource.NESTED_CONTROLLER, route);
|
|
|
|
|
|
- try {
|
|
|
+ try (Scope ignore = otelContext.with(ROUTE_KEY, route).makeCurrent()) {
|
|
|
handler.handle(context);
|
|
|
} catch (Throwable throwable) {
|
|
|
Span serverSpan = LocalRootSpan.fromContextOrNull(otelContext);
|
|
@@ -47,7 +53,9 @@ public final class RoutingContextHandlerWrapper implements Handler<RoutingContex
|
|
|
}
|
|
|
|
|
|
private static String getRoute(Context otelContext, RoutingContext routingContext) {
|
|
|
- return routingContext.currentRoute().getPath();
|
|
|
+ String route = routingContext.currentRoute().getPath();
|
|
|
+ String existingRoute = otelContext.get(ROUTE_KEY);
|
|
|
+ return existingRoute != null ? existingRoute + route : route;
|
|
|
}
|
|
|
|
|
|
private static Throwable unwrapThrowable(Throwable throwable) {
|