Skip to content

Vert.x instrumentation is incorrect (null) for regex routes on 1.12 #5177

@akleiman

Description

@akleiman

When the route is a regex path it doesn't have a path attribute. Class datadog.trace.instrumentation.vertx_4_0.server.RouteHandlerWrapper reads the property and inserts it in the routing context:

  private void updateRoutingContextWithRoute(RoutingContext routingContext) {
    final String method = routingContext.request().method().name();
    final String mountPoint = routingContext.mountPoint();

    String path = routingContext.currentRoute().getPath();

    if (mountPoint != null) {
      final String noBackslashhMountPoint =
          mountPoint.endsWith("/")
              ? mountPoint.substring(0, mountPoint.lastIndexOf("/"))
              : mountPoint;
      path = noBackslashhMountPoint + path;
    }
    if (method != null && path != null) {
      routingContext.put(ROUTE_CONTEXT_KEY, path);
    }
  }

The result is that under resources a regex path shows up as "parentSpan" + null, i.e.: GET /apinull.

I think a viable solution would be to check
Route.isRegexPath() and if true, use routingContext.currentRoute().getName(), perhaps like:

  private void updateRoutingContextWithRoute(RoutingContext routingContext) {
    final String method = routingContext.request().method().name();
    final String mountPoint = routingContext.mountPoint();

    Route = routingContext.currentRoute();
    String path;
    if(route.isRegexPath()) {
      path = routingContext.currentRoute().getName();
    } else {
      path = routingContext.currentRoute().getPath();
    }
    

    if (mountPoint != null) {
      final String noBackslashhMountPoint =
          mountPoint.endsWith("/")
              ? mountPoint.substring(0, mountPoint.lastIndexOf("/"))
              : mountPoint;
      path = noBackslashhMountPoint + path;
    }
    if (method != null && path != null) {
      routingContext.put(ROUTE_CONTEXT_KEY, path);
    }
  }

This would produce a resource like: /api/v1/entity/{id}, at least in my testing using vertx openapi support.

Metadata

Metadata

Assignees

No one assigned

    Labels

    inst: othersAll other instrumentationsinst: vertxEclipse Vert.x instrumentation

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions