eclipse-vertx / vertx-tracing

Vertx integration with tracing libraries
Other
42 stars 34 forks source link

URISyntaxException thrown when unusual URL was encountered in OpenTelemetryTracer #74

Closed sebastianhaeni closed 8 months ago

sebastianhaeni commented 9 months ago

Version

io.vertx:vertx-opentelemetry:4.5.3

Context

When a request is made to the service with an unusual URL, an exception is thrown originating by tracing, because the URL cannot be parsed and added as a tag to the span.

Tag extraction should not throw exceptions based on non-standard URLs.

java.net.URISyntaxException: Illegal character in query at index 47: /wp-admin/admin-post.php?swp_debug=load_options&swp_url=<pre>system('cat
    at java.base/java.net.URI$Parser.fail(URI.java:2995)
    at java.base/java.net.URI$Parser.checkChars(URI.java:3166)
    at java.base/java.net.URI$Parser.parseHierarchical(URI.java:3254)
    at java.base/java.net.URI$Parser.parse(URI.java:3207)
    at java.base/java.net.URI.<init>(URI.java:645)
    at io.vertx.core.http.impl.HttpUtils.absoluteURI(HttpUtils.java:527)
    at io.vertx.core.http.impl.Http1xServerRequest.absoluteURI(Http1xServerRequest.java:390)
    at io.vertx.core.http.impl.HttpUtils$1.value(HttpUtils.java:103)
    at io.vertx.core.http.impl.HttpUtils$1.value(HttpUtils.java:78)
    at io.vertx.tracing.opentelemetry.OpenTelemetryTracer.processTags(OpenTelemetryTracer.java:175)
    at io.vertx.tracing.opentelemetry.OpenTelemetryTracer.reportTagsAndStart(OpenTelemetryTracer.java:164)
    at io.vertx.tracing.opentelemetry.OpenTelemetryTracer.receiveRequest(OpenTelemetryTracer.java:79)
    at io.vertx.tracing.opentelemetry.OpenTelemetryTracer.receiveRequest(OpenTelemetryTracer.java:33)
    at io.vertx.core.http.impl.Http1xServerRequest.reportRequestBegin(Http1xServerRequest.java:613)
    at io.vertx.core.http.impl.Http1xServerRequest.handleBegin(Http1xServerRequest.java:159)
    at io.vertx.core.http.impl.Http1xServerConnection.handleMessage(Http1xServerConnection.java:172)
    at [io.vertx.core.net](http://io.vertx.core.net/).impl.ConnectionBase.read(ConnectionBase.java:159)
    at [io.vertx.core.net](http://io.vertx.core.net/).impl.VertxHandler.channelRead(VertxHandler.java:153)

Do you have a reproducer?

Example URL: /wp-admin/admin-post.php?swp_debug=load_options&swp_url=<pre>system('cat

Steps to reproduce

  1. Instrument application with vertx-opentelemetry
  2. Make a request with the above URL
  3. URISyntaxException exception gets thrown

HttpUtils.value(...) I assume is okay if it throws. But the tag extraction should not throw. I.e. it needs to use another mechanism than HttpUtils or catch the exception and use a fallback value.

tsegismont commented 9 months ago

Thanks for the report

tsegismont commented 8 months ago

For clarification, the URISyntaxException is logged by Http1xServerRequest#absoluteURI, which returns a null value in this case. Tags data is still extracted and, for OpenTelemetry, the absolute URL is not a required attribute.

An issue related to the absoluteUri method has already been filed to Vert.x core: https://github.com/eclipse-vertx/vert.x/issues/2797

Before it is fixed and to avoid polluting logs, you can change the log level of io.vertx.core.http.impl.Http1xServerRequest.

tsegismont commented 8 months ago

Fixed by https://github.com/eclipse-vertx/vert.x/pull/5158