SimpleFixedSizeExemplarReservoir implements ExemplarReservoir
Fixed-size reservoir using Algorithm R for uniform sampling.
This reservoir keeps up to N exemplars, using reservoir sampling to ensure that each measurement has an equal probability of being selected when more than N measurements are offered.
This is appropriate for Counter, Gauge, and UpDownCounter instruments where bucket alignment is not meaningful.
Tags
Interfaces
- ExemplarReservoir
- Stores a bounded collection of exemplars for metric aggregation.
Methods
- __construct() : mixed
- collect() : array<string|int, Exemplar>
- Collect all stored exemplars.
- offer() : void
- Offer a measurement for potential storage as an exemplar.
- reset() : void
- Clear all stored exemplars.
Methods
__construct()
public
__construct([int $size = 1 ]) : mixed
Parameters
- $size : int = 1
-
Maximum number of exemplars to store (default: 1)
collect()
Collect all stored exemplars.
public
collect([bool $reset = true ]) : array<string|int, Exemplar>
Parameters
- $reset : bool = true
-
Whether to clear the reservoir after collection
Return values
array<string|int, Exemplar>offer()
Offer a measurement for potential storage as an exemplar.
public
offer(int|float $value, array<string|int, mixed> $attributes, SpanContext $context, DateTimeImmutable $timestamp[, int $bucketIndex = 0 ]) : void
The reservoir decides whether to keep this measurement based on its sampling strategy. Not all offered measurements will be stored.
Parameters
- $value : int|float
-
The measurement value
- $attributes : array<string|int, mixed>
-
The measurement attributes
- $context : SpanContext
-
The span context for trace correlation
- $timestamp : DateTimeImmutable
-
When the measurement was recorded
- $bucketIndex : int = 0
-
For histogram buckets, the bucket index; ignored by other reservoirs
reset()
Clear all stored exemplars.
public
reset() : void