@ThreadSafe public interface LongValueObserver extends AsynchronousInstrument<AsynchronousInstrument.LongResult>
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.getMeterProvider().get("my_library_name");
private static final LongValueObserver cpuObserver =
meter.
.longValueObserverBuilder("cpu_fan_speed")
.setDescription("System CPU fan speed")
.setUnit("ms")
.build();
void init() {
cpuObserver.setCallback(
new LongValueObserver.Callback<LongResult>() {
{@literal @}Override
public void update(LongResult result) {
// Get system cpu fan speed
result.observe(cpuFanSpeed);
}
});
}
}
Modifier and Type | Interface and Description |
---|---|
static interface |
LongValueObserver.Builder
Builder class for
LongValueObserver . |
AsynchronousInstrument.Callback<R extends AsynchronousInstrument.Result>, AsynchronousInstrument.DoubleResult, AsynchronousInstrument.LongResult, AsynchronousInstrument.Result
Modifier and Type | Method and Description |
---|---|
void |
setCallback(AsynchronousInstrument.Callback<AsynchronousInstrument.LongResult> callback)
Sets a callback that gets executed every collection interval.
|
void setCallback(AsynchronousInstrument.Callback<AsynchronousInstrument.LongResult> callback)
AsynchronousInstrument
Evaluation is deferred until needed, if this AsynchronousInstrument
metric is not
exported then it will never be called.
setCallback
in interface AsynchronousInstrument<AsynchronousInstrument.LongResult>
callback
- the callback to be executed before export.