java.lang.Object
org.apache.juneau.rest.server.observation.Observer

public final class Observer extends Object
Factory for custom (non-request) Observations, composing a MetricsRecorder and a TracerHook.

This is the explicit programmatic observation substrate for juneau-rest-server: it reuses the exact same two SPIs the request path uses (MetricsRecorder, TracerHook) and the same metricName / metricTags comma-separated tag model, but is decoupled from RestRequest so application code can instrument an arbitrary block of work. Juneau deliberately has no method-interception / AOP substrate, so observation is explicit (a try-with-resources block) rather than annotation-driven — consistent with the framework's explicit-over-magic philosophy.

No-backend contract

An Observer built from the no-op SPIs (NOOP) never takes a timestamp and hands back Observation.NOOP, so an observation in an unconfigured process costs nothing beyond the try-with-resources scaffolding. start(String, String) short-circuits to the no-op handle whenever both backends are the no-op singletons.

Wiring

Typically obtained from a RestContext's bean store — register the same @Bean MetricsRecorder / @Bean TracerHook you already register for request-path observability, then build an Observer from them (or install one as the Observations default). Construct directly for tests:

Observer o = new Observer(new MicrometerMetricsRecorder(registry), new OtelTracerHook(otel));

See Also:
Since:
10.0.0
  • Field Details

  • Constructor Details

  • Method Details

    • start

      public Observation start(String name, String tags)
      Starts a new observation.

      When both backends are the no-op singletons this returns Observation.NOOP without taking a timestamp or opening a span. Otherwise it opens a span via TracerHook.startSpan(String) and captures a start timestamp; the paired timer sample is recorded on Observation.close().

      Parameters:
      name - The observation name — used as both the span name and the metric timer name. Must not be null or blank.
      tags - Additional metric tags as comma-separated key=value pairs (e.g. "team=payments,region=us-east"), or null / empty for none.
      Returns:
      The started Observation. Never null.
    • isActive

      public boolean isActive()
      Returns whether this observer has at least one live backend (metrics or tracing).
      Returns:
      true if either the metrics recorder or the tracer is non-no-op.