forked from open-telemetry/opentelemetry-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DoubleValueObserver.java
61 lines (55 loc) · 1.77 KB
/
DoubleValueObserver.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/
package io.opentelemetry.metrics;
import io.opentelemetry.metrics.AsynchronousInstrument.DoubleResult;
import javax.annotation.concurrent.ThreadSafe;
/**
* {@code ValueObserver} is the asynchronous instrument corresponding to ValueRecorder, used to
* capture values that are treated as individual observations, recorded with the observe(value)
* method.
*
* <p>A {@code 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.
*
* <p>Example:
*
* <pre>{@code
* class YourClass {
*
* private static final Meter meter = OpenTelemetry.getMeterProvider().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<DoubleResult>() {
* {@literal @}Override
* public void update(DoubleResult result) {
* // Get system cpu temperature
* result.observe(cpuTemperature);
* }
* });
* }
* }
* }</pre>
*/
@ThreadSafe
public interface DoubleValueObserver extends AsynchronousInstrument<DoubleResult> {
@Override
void setCallback(Callback<DoubleResult> callback);
/** Builder class for {@link DoubleValueObserver}. */
interface Builder extends AsynchronousInstrument.Builder {
@Override
Builder setDescription(String description);
@Override
Builder setUnit(String unit);
@Override
DoubleValueObserver build();
}
}