MetricReader behaviour and collection pipeline.
A MetricReader collects metrics from the SDK's aggregation state, runs async callbacks, and delivers collected data to an exporter.
Collection produces a list of metric maps, each containing the stream identity, resource, scope, and data points.
Concurrency
Spec metrics/sdk.md L1880-L1881 (Status: Stable) —
"Collect, ForceFlush (for periodic exporting MetricReader)
and Shutdown MUST be safe to be called concurrently."
Implementing modules MUST be safe for concurrent invocation
of these three callbacks. The built-in
Otel.SDK.Metrics.MetricReader.PeriodicExporting serialises
via its GenServer mailbox, satisfying the MUST.
Deferred Development-status features
- MetricFilter. Spec
metrics/sdk.mdL1308 (Status: Development) describes aMetricFilterapplied to metrics and attributes duringMetricReader#Collect. Not implemented — no:metric_filterfield on reader configs;MetricProducer.produce/1callback has no filter parameter. Waits for spec stabilisation.
Summary
Types
Reader-implementer config — the value passed to a reader's
start_link/1 callback. Each implementation defines its own
shape; the alias names the boundary so callers (notably
Otel.SDK.Metrics.MeterProvider) can refer to it in @specs
rather than the bare map() literal.
Types
@type config() :: map()
Reader-implementer config — the value passed to a reader's
start_link/1 callback. Each implementation defines its own
shape; the alias names the boundary so callers (notably
Otel.SDK.Metrics.MeterProvider) can refer to it in @specs
rather than the bare map() literal.
@type metric() :: %{ name: String.t(), description: String.t(), unit: String.t(), scope: Otel.API.InstrumentationScope.t(), resource: Otel.SDK.Resource.t(), kind: Otel.API.Metrics.Instrument.kind(), temporality: Otel.API.Metrics.Instrument.temporality() | nil, is_monotonic: boolean() | nil, datapoints: [Otel.SDK.Metrics.Aggregation.datapoint()] }
Callbacks
@callback force_flush(server :: GenServer.server()) :: :ok | {:error, term()}
@callback shutdown(server :: GenServer.server()) :: :ok | {:error, term()}
@callback start_link(config :: config()) :: GenServer.on_start()