Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ muzzle {

dependencies {
compileOnly("io.vertx:vertx-web:3.0.0")
compileOnly("io.vertx:vertx-codegen:3.0.0")
compileOnly("io.vertx:vertx-docgen:3.0.0")

// We need both version as different versions of Vert.x use different versions of Netty
testInstrumentation(project(":instrumentation:netty:netty-4.0:javaagent"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@

package io.opentelemetry.javaagent.instrumentation.vertx;

import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.context.Context;
import io.opentelemetry.context.Scope;
import io.opentelemetry.context.propagation.TextMapSetter;
import io.opentelemetry.instrumentation.api.instrumenter.LocalRootSpan;
import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRoute;
import io.opentelemetry.instrumentation.api.semconv.http.HttpServerRouteSource;
import io.vertx.core.Handler;
import io.vertx.core.http.HttpServerRequest;
import io.vertx.ext.web.RoutingContext;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.UndeclaredThrowableException;
Expand All @@ -37,6 +40,7 @@ public void handle(RoutingContext context) {
route = route.substring(0, route.length() - 1);
}
HttpServerRoute.update(otelContext, HttpServerRouteSource.NESTED_CONTROLLER, route);
injectContextToDownstream(otelContext, context.request());

try (Scope ignore = RouteHolder.init(otelContext, route).makeCurrent()) {
handler.handle(context);
Expand All @@ -49,6 +53,21 @@ public void handle(RoutingContext context) {
}
}

private static void injectContextToDownstream(
Context otelContext, HttpServerRequest serverRequest) {
TextMapSetter<HttpServerRequest> setter =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the typical pattern is injecting context using TextMapSetters is something that happens in a client as opposed to server instrumentation

(carrier, key, value) -> {
if (carrier != null) {
carrier.headers().set(key, value);
}
};

GlobalOpenTelemetry.get()
.getPropagators()
.getTextMapPropagator()
.inject(otelContext, serverRequest, setter);
}

private static String getRoute(Context otelContext, RoutingContext routingContext) {
String route = routingContext.currentRoute().getPath();
String existingRoute = RouteHolder.get(otelContext);
Expand Down
Loading