Interface LongValueRecorder
-
- All Superinterfaces:
Instrument
,SynchronousInstrument<BoundLongValueRecorder>
@ThreadSafe public interface LongValueRecorder extends SynchronousInstrument<BoundLongValueRecorder>
ValueRecorder is a synchronous instrument useful for recording any number, positive or negative. Values captured by a Record(value) are treated as individual events belonging to a distribution that is being summarized.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); } }
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description BoundLongValueRecorder
bind(Labels labels)
Returns aBound Instrument
associated with the specified labels.void
record(long value)
Records the given measurement, associated with the currentContext
and empty labels.void
record(long value, Labels labels)
Records the given measurement, associated with the currentContext
and provided set of labels.
-
-
-
Method Detail
-
record
void record(long value, Labels labels)
Records the given measurement, associated with the currentContext
and provided set of labels.- Parameters:
value
- the measurement to record.labels
- the set of labels to be associated to this recording- Throws:
IllegalArgumentException
- if value is negative.
-
record
void record(long value)
Records the given measurement, associated with the currentContext
and empty labels.- Parameters:
value
- the measurement to record.- Throws:
IllegalArgumentException
- if value is negative.
-
bind
BoundLongValueRecorder bind(Labels labels)
Description copied from interface:SynchronousInstrument
Returns aBound Instrument
associated with the specified labels. Multiples requests with the same set of labels may return the sameBound Instrument
instance.It is recommended that callers keep a reference to the Bound Instrument instead of always calling this method for every operation.
- Specified by:
bind
in interfaceSynchronousInstrument<BoundLongValueRecorder>
- Parameters:
labels
- the set of labels, as key-value pairs.- Returns:
- a
Bound Instrument
-
-