Class Observer
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
See Also:
- Since:
- 10.0.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ObserverObserver backed by the no-op metrics recorder and tracer — produces onlyObservation.NOOP. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanisActive()Returns whether this observer has at least one live backend (metrics or tracing).Starts a new observation.
-
Field Details
-
NOOP
Observer backed by the no-op metrics recorder and tracer — produces onlyObservation.NOOP.
-
-
Constructor Details
-
Observer
Constructor.- Parameters:
recorder- The metrics recorder to time observations against. Must not benull ; useNoOpMetricsRecorder.INSTANCEto disable metrics.tracer- The tracer to open spans against. Must not benull ; useNoOpTracerHook.INSTANCEto disable tracing.
-
-
Method Details
-
start
Starts a new observation.When both backends are the no-op singletons this returns
Observation.NOOPwithout taking a timestamp or opening a span. Otherwise it opens a span viaTracerHook.startSpan(String)and captures a start timestamp; the paired timer sample is recorded onObservation.close().- Parameters:
name- The observation name — used as both the span name and the metric timer name. Must not benull or blank.tags- Additional metric tags as comma-separatedkey=valuepairs (e.g."team=payments,region=us-east"), ornull / empty for none.- Returns:
- The started
Observation. Nevernull .
-
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.
-