Class RouteTagResolver
java.lang.Object
com.vaadin.observability.micrometer.RouteTagResolver
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 -
Method Summary
Modifier and TypeMethodDescriptionResolves 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 thatorders/17andorders/18share one tag value.tagForTemplate(String template) Bucketizes an already-resolved route template against the cardinality limit.Resolves the tag value for the view a UI currently shows.templateForActiveRoute(com.vaadin.flow.component.UI ui) LiketagForActiveRoute(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.
-
Constructor Details
-
RouteTagResolver
public RouteTagResolver(int limit)
-
-
Method Details
-
tagFor
Resolves the tag value for a navigation target.nullinput 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 needsVaadinSession.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 thoughtagFor(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 benullregistry- the registry to resolve the template from, may benull- Returns:
- the tag value, never
null
-
tagForUi
Resolves the tag value for the view a UI currently shows.- Parameters:
ui- the UI, may benullfallback- returned when no navigation target can be resolved- Returns:
- the tag value, or
fallback
-
tagForActiveRoute
Resolves the tag value for the view a UI currently shows, preferring the route template of the innermost active navigation target so thatorders/17andorders/18share one tag value. Falls back to the concrete location when no navigation target can be resolved, and toMeterNames.ROUTE_UNKNOWNwhen 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 benull- Returns:
- the route tag value, never
null
-
templateForActiveRoute
LiketagForActiveRoute(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 theuritag onhttp.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 benull- Returns:
- the route template tag value, or
MeterNames.ROUTE_UNKNOWNwhen no navigation target can be resolved
-
tagForTemplate
Bucketizes an already-resolved route template against the cardinality limit. Useful when the template is already known and we only need the overflow behavior.
-