Interface Observation
- All Superinterfaces:
AutoCloseable
Returned by Observer.start(String, String) and by the Observations facade. An
observation pairs a metric timer with a tracing span around an arbitrary block of work that has no
associated HTTP request — the request-path equivalent is the framework-driven boundary in
RestOpInvoker.
Usage
The handle is AutoCloseable and is designed for try-with-resources. On close() it
records the elapsed time to the metrics recorder and ends the span. Mark a failure with
setError(Throwable) before the block exits so both the timer's exception tag and the
span's error status reflect it:
No-backend contract
When no metrics recorder / tracer is installed, Observations hands back
NOOP — a process-wide singleton whose methods do nothing and whose timing is never
taken, so an observation in an unconfigured process costs nothing beyond the try-with-resources
scaffolding.
- Since:
- 10.0.0
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ObservationProcess-wide no-op observation, returned whenever no backend is installed. -
Method Summary
-
Field Details
-
NOOP
Process-wide no-op observation, returned whenever no backend is installed.Drops the error on the floor and does nothing on close.
-
-
Method Details
-
setError
Marks the observed block as failed.The throwable is surfaced as the metric timer's
exceptiontag and recorded on the tracing span (statusERROR+exception.typeattribute) when the observation closes. Safe to call at most once; anullargument is treated as "no error".- Parameters:
error- The exception that caused the block to fail. May benull (treated as success).
-
close
void close()Closes the observation — records the elapsed timer sample and ends the span.Always called via the try-with-resources
finallycontract. Implementations must not throw.- Specified by:
closein interfaceAutoCloseable
-