Aggregation behaviour and default instrument-to-aggregation
mapping (metrics/sdk.md §Aggregation L612-L860).
Public API
| Callback | Role |
|---|---|
aggregate/4 | SDK (OTel API MUST) — record a measurement into an ETS-backed cell |
collect/3 | SDK (OTel API MUST) — emit datapoints for the configured temporality |
References
- OTel Metrics SDK §Aggregation:
opentelemetry-specification/specification/metrics/sdk.mdL612-L860 - Built-in implementations:
Otel.SDK.Metrics.Aggregation.{Drop,Sum,LastValue,ExplicitBucketHistogram}
Summary
Types
Per-stream-per-attribute-set aggregation key.
Stream-level identity used by collect/3 callbacks — the
(name, scope) prefix of agg_key/0, without the reader
or attribute selection.
Types
@type agg_key() :: {name :: String.t(), scope :: Otel.API.InstrumentationScope.t(), reader_id :: reference() | nil, attributes :: %{required(String.t()) => primitive_any()}}
Per-stream-per-attribute-set aggregation key.
Used as the ETS key in the metrics table to identify a single
aggregation cell — combining stream identity (name + scope),
the reader the aggregation belongs to, and the attribute set
the cell aggregates over. Constructed at every aggregate/4
call site (e.g. Otel.SDK.Metrics.Meter) and at exemplar
reservoir lookups.
@type datapoint() :: %{ attributes: %{required(String.t()) => primitive_any()}, value: term(), start_time: non_neg_integer(), time: non_neg_integer() }
@type primitive_any() :: primitive() | [primitive_any()] | %{required(String.t()) => primitive_any()}
@type stream_key() :: {name :: String.t(), scope :: Otel.API.InstrumentationScope.t()}
Stream-level identity used by collect/3 callbacks — the
(name, scope) prefix of agg_key/0, without the reader
or attribute selection.
Callbacks
@callback aggregate( metrics_tab :: :ets.table(), key :: agg_key(), value :: number(), opts :: map() ) :: :ok
@callback collect( metrics_tab :: :ets.table(), stream_key :: stream_key(), opts :: map() ) :: [datapoint()]
Functions
@spec default_for(kind :: Otel.API.Metrics.Instrument.kind()) :: module()