Class RouteTagResolver

java.lang.Object
com.vaadin.observability.micrometer.RouteTagResolver

public final class RouteTagResolver extends Object
Maps a Flow navigation target to a low-cardinality tag value suitable for Micrometer. Resolves the route template (e.g. users/:id) rather than the resolved URL, then enforces an upper bound on the number of distinct values it will admit; further values are bucketed under MeterNames.ROUTE_OTHER.
  • Constructor Summary

    Constructors
    Constructor
    Description
    RouteTagResolver(int limit)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    tagFor(Class<? extends com.vaadin.flow.component.Component> navigationTarget)
    Resolves the tag value for a navigation target.
    tagFor(Class<? extends com.vaadin.flow.component.Component> navigationTarget, com.vaadin.flow.server.RouteRegistry registry)
    Resolves the tag value for a navigation target against an explicit route registry.
    tagForActiveRoute(com.vaadin.flow.component.UI ui)
    Resolves the tag value for the view a UI currently shows, preferring the route template of the innermost active navigation target so that orders/17 and orders/18 share one tag value.
    Bucketizes an already-resolved route template against the cardinality limit.
    tagForUi(com.vaadin.flow.component.UI ui, String fallback)
    Resolves the tag value for the view a UI currently shows.
    templateForActiveRoute(com.vaadin.flow.component.UI ui)
    Like tagForActiveRoute(UI) but without the concrete-location fallback: the result is always a route template (or the class-simple-name stand-in), never a literal path with its parameter values.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • RouteTagResolver

      public RouteTagResolver(int limit)
  • Method Details

    • tagFor

      public String tagFor(Class<? extends com.vaadin.flow.component.Component> navigationTarget)
      Resolves the tag value for a navigation target. null input is treated as an unknown route.
    • tagFor

      public String tagFor(Class<? extends com.vaadin.flow.component.Component> navigationTarget, com.vaadin.flow.server.RouteRegistry registry)
      Resolves the tag value for a navigation target against an explicit route registry.

      Use this when the caller may run off the request thread. The session-scoped lookup that tagFor(Class) falls back on needs VaadinSession.getCurrent(), which is unset there, so such a caller would silently get the class simple name instead of the template.

      The trade is that a UI's router carries the application registry, while the session registry layers over it. A route registered with RouteConfiguration.forSessionScope().setRoute(...) is therefore not resolvable here and falls back to the class simple name, even though tagFor(Class) would find it. Reading the session registry instead is not an option for those callers: it needs the session lock, which the executor thread a fetch runs on does not hold.

      Parameters:
      navigationTarget - the navigation target, may be null
      registry - the registry to resolve the template from, may be null
      Returns:
      the tag value, never null
    • tagForUi

      public String tagForUi(com.vaadin.flow.component.UI ui, String fallback)
      Resolves the tag value for the view a UI currently shows.
      Parameters:
      ui - the UI, may be null
      fallback - returned when no navigation target can be resolved
      Returns:
      the tag value, or fallback
    • tagForActiveRoute

      public String tagForActiveRoute(com.vaadin.flow.component.UI ui)
      Resolves the tag value for the view a UI currently shows, preferring the route template of the innermost active navigation target so that orders/17 and orders/18 share one tag value. Falls back to the concrete location when no navigation target can be resolved, and to MeterNames.ROUTE_UNKNOWN when there is no UI or its state cannot be read (for example because it has been detached).
      Parameters:
      ui - the UI to resolve the active route of, may be null
      Returns:
      the route tag value, never null
    • templateForActiveRoute

      public String templateForActiveRoute(com.vaadin.flow.component.UI ui)
      Like tagForActiveRoute(UI) but without the concrete-location fallback: the result is always a route template (or the class-simple-name stand-in), never a literal path with its parameter values. For a consumer whose tag values must stay bounded — such as the uri tag on http.server.requests — the location fallback would be the one genuinely unbounded source (orders/17, orders/18, …).
      Parameters:
      ui - the UI to resolve the active route of, may be null
      Returns:
      the route template tag value, or MeterNames.ROUTE_UNKNOWN when no navigation target can be resolved
    • tagForTemplate

      public String tagForTemplate(String template)
      Bucketizes an already-resolved route template against the cardinality limit. Useful when the template is already known and we only need the overflow behavior.