@ThreadSafe public interface LongValueRecorder extends SynchronousInstrument<LongValueRecorder.BoundLongValueRecorder>
ValueRecorder should be chosen either when capturing measurements that do not contribute meaningfully to a sum, or when capturing numbers that are additive in nature, but where the distribution of individual increments is considered interesting.
One of the most common uses for ValueRecorder is to capture latency measurements. Latency measurements are not additive in the sense that there is little need to know the latency-sum of all processed requests. We use a ValueRecorder instrument to capture latency measurements typically because we are interested in knowing mean, median, and other summary statistics about individual events.
Example:
class YourClass {
private static final Meter meter = OpenTelemetry.getMeterProvider().get("my_library_name");
private static final LongValueRecorder valueRecorder =
meter.
.longValueRecorderBuilder("doWork_latency")
.setDescription("gRPC Latency")
.setUnit("ns")
.build();
// It is recommended that the API user keep a reference to a Bound Counter.
private static final BoundLongValueRecorder someWorkBound =
valueRecorder.bind("work_name", "some_work");
void doWork() {
long startTime = System.nanoTime();
// Your code here.
someWorkBound.record(System.nanoTime() - startTime);
}
}
Modifier and Type | Interface and Description |
---|---|
static interface |
LongValueRecorder.BoundLongValueRecorder
A
Bound Instrument for a LongValueRecorder . |
static interface |
LongValueRecorder.Builder
Builder class for
LongValueRecorder . |
SynchronousInstrument.BoundInstrument
Modifier and Type | Method and Description |
---|---|
LongValueRecorder.BoundLongValueRecorder |
bind(Labels labels)
Returns a
Bound Instrument associated with the specified labels. |
void |
record(long value)
Records the given measurement, associated with the current
Context and empty labels. |
void |
record(long value,
Labels labels)
Records the given measurement, associated with the current
Context and provided set of
labels. |
void record(long value, Labels labels)
Context
and provided set of
labels.value
- the measurement to record.labels
- the set of labels to be associated to this recordingjava.lang.IllegalArgumentException
- if value is negative.void record(long value)
Context
and empty labels.value
- the measurement to record.java.lang.IllegalArgumentException
- if value is negative.LongValueRecorder.BoundLongValueRecorder bind(Labels labels)
SynchronousInstrument
Bound Instrument
associated with the specified labels. Multiples requests
with the same set of labels may return the same Bound Instrument
instance.
It is recommended that callers keep a reference to the Bound Instrument instead of always calling this method for every operation.
bind
in interface SynchronousInstrument<LongValueRecorder.BoundLongValueRecorder>
labels
- the set of labels, as key-value pairs.Bound Instrument