Class MetricsServiceInitListener

java.lang.Object
com.vaadin.observability.micrometer.MetricsServiceInitListener
All Implemented Interfaces:
com.vaadin.flow.server.VaadinServiceInitListener, Serializable, EventListener

public class MetricsServiceInitListener extends Object implements com.vaadin.flow.server.VaadinServiceInitListener
Wires Observability Kit instrumentation into a VaadinService at initialization.

Three construction paths:

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 Details

    • MetricsServiceInitListener

      public MetricsServiceInitListener()
      Constructor used by ServiceLoader. Resolves the registry, observation registry, and settings lazily from ObservabilityKit.
    • MetricsServiceInitListener

      public MetricsServiceInitListener(io.micrometer.core.instrument.MeterRegistry meterRegistry, ObservabilitySettings settings)
      Constructor used by DI containers that don't provide an ObservationRegistry.
      Parameters:
      meterRegistry - Micrometer meter registry, not null
      settings - instrumentation settings, not null
    • 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, not null
      observationRegistry - Micrometer observation registry, may be null to disable Observation-based instrumentation
      settings - instrumentation settings, not null
  • Method Details

    • installDefaultObservationHandlers

      protected void installDefaultObservationHandlers(io.micrometer.observation.ObservationRegistry observationRegistry, io.micrometer.core.instrument.MeterRegistry meterRegistry)
      Registers default ObservationHandlers that make Observations produce Timers.

      The default implementation installs DefaultMeterObservationHandler. Spring Boot deployments override this method to no-op because the Boot Actuator's ObservationAutoConfiguration already registers the same handler.

      Parameters:
      observationRegistry - the registry to configure
      meterRegistry - 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's ServerHttpObservationFilter span) with Vaadin-specific information so the parent HTTP span renders informatively in the trace UI. Called from RequestMetricsBinder at the end of the request, once the request handler has settled the Vaadin request type, and before the framework stops its HTTP observation.

      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 request
      requestType - the classified request type (e.g. uidl, heartbeat, push, bootstrap, stream, 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's ServerHttpObservationFilter span) as errored. Called from RequestMetricsBinder when 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 request
      failure - the exception Vaadin request handling raised, never null
    • 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's ServerHttpObservationFilter span), so the uri tag on http.server.requests and the HTTP span name carry the view (e.g. /orders/:id) instead of the protocol-level /vaadin/uidl. Called from RequestMetricsBinder at 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 request
      routeTemplate - the resolved route template; blank means the root route
    • serviceInit

      public void serviceInit(com.vaadin.flow.server.ServiceInitEvent event)
      Specified by:
      serviceInit in interface com.vaadin.flow.server.VaadinServiceInitListener