@ThreadSafe public interface DoubleValueObserver extends AsynchronousInstrument<DoubleValueObserver.ResultDoubleValueObserver>
ValueObserver is the asynchronous instrument corresponding to ValueRecorder, used to
capture values that are treated as individual observations, recorded with the observe(value)
method.
A ValueObserver is a good choice in situations where a measurement is expensive to
compute, such that it would be wasteful to compute on every request.
Example:
class YourClass {
private static final Meter meter = OpenTelemetry.getMeterRegistry().get("my_library_name");
private static final DoubleValueObserver cpuObserver =
meter.
.doubleValueObserverBuilder("cpu_temperature")
.setDescription("System CPU temperature")
.setUnit("ms")
.build();
void init() {
cpuObserver.setCallback(
new DoubleValueObserver.Callback<ResultDoubleValueObserver>() {
{@literal @}Override
public void update(ResultDoubleValueObserver result) {
// Get system cpu temperature
result.observe(cpuTemperature);
}
});
}
}
| Modifier and Type | Interface and Description |
|---|---|
static interface |
DoubleValueObserver.Builder
Builder class for
DoubleValueObserver. |
static interface |
DoubleValueObserver.ResultDoubleValueObserver
The result for the
Callback. |
AsynchronousInstrument.Callback<R>| Modifier and Type | Method and Description |
|---|---|
void |
setCallback(AsynchronousInstrument.Callback<DoubleValueObserver.ResultDoubleValueObserver> callback)
Sets a callback that gets executed every collection interval.
|
void setCallback(AsynchronousInstrument.Callback<DoubleValueObserver.ResultDoubleValueObserver> callback)
AsynchronousInstrumentEvaluation is deferred until needed, if this AsynchronousInstrument metric is not
exported then it will never be called.
setCallback in interface AsynchronousInstrument<DoubleValueObserver.ResultDoubleValueObserver>callback - the callback to be executed before export.