Otel.SDK.Metrics.MetricExporter behaviour (otel v0.2.0)

Copy Markdown View Source

Behaviour for push metric exporters.

Exporters receive batches of collected metrics and transmit them to a backend. Export calls are serialized by the MetricReader.

Concurrency

Spec metrics/sdk.md L1883-L1884 (Status: Stable) — "ForceFlush and Shutdown MUST be safe to be called concurrently." export/2 is called serially by the MetricReader (see moduledoc above) so the MUST is on force_flush/1 and shutdown/1 callbacks; implementations MUST handle a force_flush arriving while another force_flush (from a different caller) or shutdown is in progress.

Summary

Types

state()

@type state() :: term()

Callbacks

export(metrics, state)

@callback export(
  metrics :: [Otel.SDK.Metrics.MetricReader.metric()],
  state :: state()
) :: :ok | :error

force_flush(state)

@callback force_flush(state :: state()) :: :ok

init(config)

@callback init(config :: term()) :: {:ok, state()} | :ignore

shutdown(state)

@callback shutdown(state :: state()) :: :ok