Class Observations
Observer for ergonomic custom
(non-request) observations.
juneau-rest-server has no method-interception / AOP substrate, so custom observations are
explicit: wrap the block of work in a try-with-resources over observe(String, String).
This mirrors how the request path is instrumented (the framework opens / closes the observation around
the @RestOp handler) but lets application code instrument arbitrary work.
Installing a backend
The default observer is Observer.NOOP until a backend is installed via install(Observer)
— typically once at startup, after the application's MetricsRecorder / TracerHook
beans are known. Until then (and in any process that never installs one) observe(String, String)
hands back Observation.NOOP and costs nothing.
Code that prefers explicit dependency injection over a global can hold an Observer directly
(resolved from the RestContext bean store) and call Observer.start(String, String) —
this facade is a convenience, not the only entry point.
See Also:
- Since:
- 10.0.0
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidInstalls the process-wide defaultObserverused byobserve(String, String).static ObservationStarts a custom observation with no additional tags.static ObservationStarts a custom observation against the installed defaultObserver.static Observerobserver()Returns the currently-installed defaultObserver.static voidreset()Resets the process-wide default observer back toObserver.NOOP.
-
Method Details
-
install
Installs the process-wide defaultObserverused byobserve(String, String).Intended to be called once at application startup. Passing
Observer.NOOP(or callingreset()) restores the no-op default.- Parameters:
observer- The observer to install. Must not benull .
-
reset
Resets the process-wide default observer back toObserver.NOOP. -
observer
Returns the currently-installed defaultObserver.- Returns:
- The default observer;
Observer.NOOPif none was installed. Nevernull .
-
observe
Starts a custom observation against the installed defaultObserver.- 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, ornull / empty for none.- Returns:
- The started
Observation(a try-with-resources handle). Nevernull .
-
observe
Starts a custom observation with no additional tags.- Parameters:
name- The observation name. Must not benull or blank.- Returns:
- The started
Observation. Nevernull .
-