Observable Instrument Types
otel4s provides three types of observable instruments:- ObservableCounter - monotonic, for values that only increase
- ObservableUpDownCounter - non-monotonic, for values that can increase or decrease
- ObservableGauge - for non-additive snapshot values
ObservableCounter
A monotonic observable counter that records increasing values.Type Signature
Creating an ObservableCounter
ObservableUpDownCounter
A non-monotonic observable counter for values that can increase or decrease.Type Signature
Creating an ObservableUpDownCounter
ObservableGauge
An observable gauge for non-additive values.Type Signature
Creating an ObservableGauge
Builder Methods
All observable instruments share the same builder methods:withUnit
Sets the unit of measure for this instrument.The measurement unit. Must be 63 or fewer ASCII characters.
Builder[F, A]
Reference: Instrument Unit
withDescription
Sets the description for this instrument.The description of the instrument.
Builder[F, A]
Reference: Instrument Description
createWithCallback
Creates an instrument with the given callback.The callback which observes measurements when invoked.
Resource[F, Observable*] (where * is Counter, UpDownCounter, or Gauge)
The callback must be:
- Short-living and (ideally) non-blocking
- Able to run in a finite amount of time
- Safe to call repeatedly, across multiple threads
create
Creates an asynchronous instrument based on an effect that produces measurements.Effect that produces a number of measurements.
Resource[F, Observable*] (where * is Counter, UpDownCounter, or Gauge)
The measurement effect must be:
- Short-living and (ideally) non-blocking
- Able to run in a finite amount of time
- Safe to call repeatedly, across multiple threads
createObserver
Creates an observer for use with batch callbacks. Returns:F[ObservableMeasurement[F, A]]
The observer must be registered via Meter.batchCallback. Values observed outside registered callbacks are ignored.
Example:
ObservableMeasurement
TheObservableMeasurement trait is used within callbacks to record measurements.
Type Signature
record
Records a value with attributes.The value to record.
The set of attributes to associate with the value.
F[Unit]
Example: