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

Copy Markdown View Source

Aggregation behaviour and default instrument-to-aggregation mapping (metrics/sdk.md §Aggregation L612-L860).

Public API

CallbackRole
aggregate/4SDK (OTel API MUST) — record a measurement into an ETS-backed cell
collect/3SDK (OTel API MUST) — emit datapoints for the configured temporality

References

  • OTel Metrics SDK §Aggregation: opentelemetry-specification/specification/metrics/sdk.md L612-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

agg_key()

@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.

datapoint()

@type datapoint() :: %{
  attributes: %{required(String.t()) => primitive_any()},
  value: term(),
  start_time: non_neg_integer(),
  time: non_neg_integer()
}

primitive()

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

primitive_any()

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

stream_key()

@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

aggregate(metrics_tab, key, value, opts)

@callback aggregate(
  metrics_tab :: :ets.table(),
  key :: agg_key(),
  value :: number(),
  opts :: map()
) :: :ok

collect(metrics_tab, stream_key, opts)

@callback collect(
  metrics_tab :: :ets.table(),
  stream_key :: stream_key(),
  opts :: map()
) :: [datapoint()]

Functions

default_for(atom)

@spec default_for(kind :: Otel.API.Metrics.Instrument.kind()) :: module()