open-telemetry / opentelemetry-java

OpenTelemetry Java SDK
https://opentelemetry.io
Apache License 2.0
2.01k stars 839 forks source link

Vert.x Web Router/SubRouter causes root span name / route to be incorrect. #6717

Closed encodedrose closed 2 months ago

encodedrose commented 2 months ago

Describe the bug I created a reproducible repo: here

When you have the following router configuration (recommended by Vertx in its docs)

Router restAPI = Router.router(vertx);

restAPI.get("/products/:productID").handler(ctx -> {

  // TODO Handle the lookup of the product....
  ctx.response().end();

});

restAPI.put("/products/:productID").handler(ctx -> {

  // TODO Add a new product...
  ctx.response().end();

});

restAPI.delete("/products/:productID").handler(ctx -> {

  // TODO delete the product...
  ctx.response().end();

});

Router mainRouter = Router.router(vertx);
mainRouter.route("/productsAPI/*").handler(k -> {
  // some logic (e.g. auth check) before passing the request to the subrouter
  k.next();
});
mainRouter.route("/productsAPI/*")
  .subRouter(restAPI);

It results in a span name: GET /productsAPI/productsAPI/products/:productID. Even though the actual route is /productsAPI/products/:productID.

Steps to reproduce

  1. Checkout the above repo or create a new vertx project with the above routing configuration 1a. The following environment variables are set:
    JAVA_TOOL_OPTIONS="-javaagent:opentelemetry-javaagent.jar";
    OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318
    OTEL_JAVAAGENT_DEBUG=true
    OTEL_SERVICE_NAME=starter
  2. Execute the curl: curl http://localhost:8888/productsAPI/products/3

What did you expect to see?

io.opentelemetry.exporter.logging.LoggingSpanExporter - 'GET /productsAPI/products/:productID'

What did you see instead? io.opentelemetry.exporter.logging.LoggingSpanExporter - 'GET /productsAPI/productsAPI/products/:productID'

What version and what artifacts are you using? pom.xml vertx: 4.5.10 opentelemtry java agent: 2.7.0

Environment Running locally for now, on macOS

Additional context All RoutingHandlers are wrapped by autoinstrumentation and this results in every RoutingHandler being appending the path. Within RoutingContextHandlerWrapper this line is responsible for the behavior.

encodedrose commented 2 months ago

Opened this in the wrong repo, closing and reopening in the opentelemetry-java-instrumentation repo.