pub trait Aggregator: Debug {
// Required methods
fn update(&self, number: &Number, descriptor: &Descriptor) -> Result<()>;
fn synchronized_move(
&self,
destination: &Arc<dyn Aggregator + Send + Sync>,
descriptor: &Descriptor,
) -> Result<()>;
fn merge(
&self,
other: &(dyn Aggregator + Send + Sync),
descriptor: &Descriptor,
) -> Result<()>;
fn as_any(&self) -> &dyn Any;
}metrics only.Expand description
Aggregator implements a specific aggregation behavior, i.e., a behavior to track a sequence of updates to an instrument. Sum-only instruments commonly use a simple Sum aggregator, but for the distribution instruments (ValueRecorder, ValueObserver) there are a number of possible aggregators with different cost and accuracy tradeoffs.
Note that any Aggregator may be attached to any instrument–this is the result of the OpenTelemetry API/SDK separation. It is possible to attach a Sum aggregator to a ValueRecorder instrument or a MinMaxSumCount aggregator to a Counter instrument.
Required Methods§
Sourcefn update(&self, number: &Number, descriptor: &Descriptor) -> Result<()>
fn update(&self, number: &Number, descriptor: &Descriptor) -> Result<()>
Update receives a new measured value and incorporates it into the aggregation. Update calls may be called concurrently.
Descriptor::number_kind should be consulted to determine whether the
provided number is an i64, u64 or f64.
The current Context could be inspected for a Baggage or
SpanContext.
Sourcefn synchronized_move(
&self,
destination: &Arc<dyn Aggregator + Send + Sync>,
descriptor: &Descriptor,
) -> Result<()>
fn synchronized_move( &self, destination: &Arc<dyn Aggregator + Send + Sync>, descriptor: &Descriptor, ) -> Result<()>
This method is called during collection to finish one period of aggregation by atomically saving the currently-updating state into the argument Aggregator.
synchronized_move is called concurrently with update. These two methods
must be synchronized with respect to each other, for correctness.
This method will return an InconsistentAggregator error if this
Aggregator cannot be copied into the destination due to an incompatible
type.
This call has no Context argument because it is expected to perform only
computation.
Sourcefn merge(
&self,
other: &(dyn Aggregator + Send + Sync),
descriptor: &Descriptor,
) -> Result<()>
fn merge( &self, other: &(dyn Aggregator + Send + Sync), descriptor: &Descriptor, ) -> Result<()>
This combines the checkpointed state from the argument Aggregator into this
Aggregator. merge is not synchronized with respect to update or
synchronized_move.
The owner of an Aggregator being merged is responsible for synchronization
of both Aggregator states.