Class MetricsServiceInitListener
- All Implemented Interfaces:
com.vaadin.flow.server.VaadinServiceInitListener,Serializable,EventListener
VaadinService at
initialization.
Three construction paths:
- Spring/Boot — instantiated as a bean with explicit
meterRegistry,observationRegistry(optional), andsettingsarguments. - Spring/Boot without observation registry — use the two-arg constructor.
- Standalone — the no-arg constructor is invoked by the Java
ServiceLoader; the registry and configuration are looked up fromObservabilityKitatserviceInittime. IfObservabilityKit.install(io.micrometer.core.instrument.MeterRegistry, com.vaadin.observability.micrometer.ObservabilitySettings)was never called, the listener silently no-ops.
When an ObservationRegistry is available and
ObservabilitySettings.isTraces() is on, the listener also wraps the
service's executor with a TracingExecutor so trace context flows
across the thread hops taken by tasks submitted to it.
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionConstructor used byServiceLoader.MetricsServiceInitListener(io.micrometer.core.instrument.MeterRegistry meterRegistry, ObservabilitySettings settings) Constructor used by DI containers that don't provide anObservationRegistry.MetricsServiceInitListener(io.micrometer.core.instrument.MeterRegistry meterRegistry, io.micrometer.observation.ObservationRegistry observationRegistry, ObservabilitySettings settings) Constructor used by DI containers. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidenrichHttpObservation(com.vaadin.flow.server.VaadinRequest request, String requestType) Hook for DI integrations to enrich the framework-level HTTP observation (e.g.protected voidenrichHttpObservationRoute(com.vaadin.flow.server.VaadinRequest request, String routeTemplate) Hook for DI integrations to set the resolved Vaadin route template on the framework-level HTTP observation (e.g.protected voidinstallDefaultObservationHandlers(io.micrometer.observation.ObservationRegistry observationRegistry, io.micrometer.core.instrument.MeterRegistry meterRegistry) Registers defaultObservationHandlers that make Observations produceTimers.protected voidmarkHttpObservationError(com.vaadin.flow.server.VaadinRequest request, Throwable failure) Hook for DI integrations to mark the framework-level HTTP observation (e.g.voidserviceInit(com.vaadin.flow.server.ServiceInitEvent event)
-
Constructor Details
-
MetricsServiceInitListener
public MetricsServiceInitListener()Constructor used byServiceLoader. Resolves the registry, observation registry, and settings lazily fromObservabilityKit. -
MetricsServiceInitListener
public MetricsServiceInitListener(io.micrometer.core.instrument.MeterRegistry meterRegistry, ObservabilitySettings settings) Constructor used by DI containers that don't provide anObservationRegistry.- Parameters:
meterRegistry- Micrometer meter registry, notnullsettings- instrumentation settings, notnull
-
MetricsServiceInitListener
public MetricsServiceInitListener(io.micrometer.core.instrument.MeterRegistry meterRegistry, io.micrometer.observation.ObservationRegistry observationRegistry, ObservabilitySettings settings) Constructor used by DI containers.- Parameters:
meterRegistry- Micrometer meter registry, notnullobservationRegistry- Micrometer observation registry, may benullto disable Observation-based instrumentationsettings- instrumentation settings, notnull
-
-
Method Details
-
installDefaultObservationHandlers
protected void installDefaultObservationHandlers(io.micrometer.observation.ObservationRegistry observationRegistry, io.micrometer.core.instrument.MeterRegistry meterRegistry) Registers defaultObservationHandlers that make Observations produceTimers.The default implementation installs
DefaultMeterObservationHandler. Spring Boot deployments override this method to no-op because the Boot Actuator'sObservationAutoConfigurationalready registers the same handler.- Parameters:
observationRegistry- the registry to configuremeterRegistry- the meter registry to attach timers to
-
enrichHttpObservation
protected void enrichHttpObservation(com.vaadin.flow.server.VaadinRequest request, String requestType) Hook for DI integrations to enrich the framework-level HTTP observation (e.g. Spring'sServerHttpObservationFilterspan) with Vaadin-specific information so the parent HTTP span renders informatively in the trace UI. Called fromRequestMetricsBinderafter the Vaadin request type has been determined and before thevaadin.request.<type>child observation is started.Default implementation no-ops, keeping the framework-agnostic core free of Spring imports. The Spring/Boot integration modules override this to call into their respective HTTP-observation APIs.
- Parameters:
request- the current Vaadin requestrequestType- the classified request type (e.g.uidl,heartbeat,push,static,other)
-
markHttpObservationError
protected void markHttpObservationError(com.vaadin.flow.server.VaadinRequest request, Throwable failure) Hook for DI integrations to mark the framework-level HTTP observation (e.g. Spring'sServerHttpObservationFilterspan) as errored. Called fromRequestMetricsBinderwhen Vaadin request handling raises an exception, and for a failure Flow routed to the session error handler (which never escapes request handling at all). For a UIDL request Vaadin swallows the exception and responds 200, so the framework would otherwise report the request as successful — while several monitoring solutions (New Relic, DataDog) only watch root or server spans for errors. For other request types Vaadin rethrows and the framework records the failure itself; there this hook merely front-runs it with the root cause.Default implementation no-ops, keeping the framework-agnostic core free of Spring imports. The Spring/Boot integration modules override this to call into their respective HTTP-observation APIs.
- Parameters:
request- the current Vaadin requestfailure- the exception Vaadin request handling raised, nevernull
-
enrichHttpObservationRoute
protected void enrichHttpObservationRoute(com.vaadin.flow.server.VaadinRequest request, String routeTemplate) Hook for DI integrations to set the resolved Vaadin route template on the framework-level HTTP observation (e.g. Spring'sServerHttpObservationFilterspan), so theuritag onhttp.server.requestsand the HTTP span name carry the view (e.g./orders/:id) instead of the protocol-level/vaadin/uidl. Called fromRequestMetricsBinderat the end of a UIDL request, once the route the request actually landed on is known. The template has already passed the route cardinality cap.Default implementation no-ops, keeping the framework-agnostic core free of Spring imports. The Spring/Boot integration modules override this to call into their respective HTTP-observation APIs.
- Parameters:
request- the current Vaadin requestrouteTemplate- the resolved route template; blank means the root route
-
serviceInit
public void serviceInit(com.vaadin.flow.server.ServiceInitEvent event) - Specified by:
serviceInitin interfacecom.vaadin.flow.server.VaadinServiceInitListener
-