Otel.SDK.Metrics.Exemplar.Reservoir.AlignedHistogramBucket (otel v0.2.0)

Copy Markdown View Source

A reservoir aligned with explicit histogram bucket boundaries.

Stores at most one exemplar per bucket. When a new measurement falls into a bucket that already has an exemplar, the existing one is replaced.

Spec compliance

Spec metrics/sdk.md L1248-L1252 — "This implementation MUST store at most one measurement that falls within a histogram bucket, and SHOULD use a uniformly-weighted sampling algorithm based on the number of measurements the bucket has seen so far ... Alternatively, the implementation MAY instead keep the last seen measurement that falls within a histogram bucket."

We implement the MAY alternative (keep last-seen) — the simpler of the two paths the spec offers. The MUST about at most one exemplar per bucket is satisfied by the %{bucket_index => exemplar} map shape.

Summary

Types

primitive()

@type primitive() ::
  String.t() | {:bytes, binary()} | boolean() | integer() | float() | nil

primitive_any()

@type primitive_any() ::
  primitive() | [primitive_any()] | %{required(String.t()) => primitive_any()}

state()

@type state() :: %{
  boundaries: [number()],
  exemplars: %{required(non_neg_integer()) => Otel.SDK.Metrics.Exemplar.t()}
}