instrument_meter (instrument v0.6.1)
View SourceOpenTelemetry-compatible MeterProvider and Meter API.
This module provides an OTel-style API for creating and using metrics, backed by the existing NIF infrastructure.
Example Usage
Meter = instrument_meter:get_meter(<<"my_service">>),
Counter = instrument_meter:create_counter(Meter, <<"requests_total">>, #{
description => <<"Total requests">>,
unit => <<"1">>
}),
instrument_meter:add(Counter, 1, #{method => <<"GET">>, status => 200}).
Summary
Functions
Adds a value to a Counter or UpDownCounter.
Adds a value to a Counter or UpDownCounter with attributes.
Invokes all observable instrument callbacks. This should be called before metrics collection to update observable values.
Creates a Counter instrument.
Creates a Counter instrument with options.
Creates a Gauge instrument.
Creates a Gauge instrument with options.
Creates a Histogram instrument.
Creates a Histogram instrument with options.
Creates an ObservableCounter with a callback. Callback can be: - 0-arity: fun() -> number() - returns a single value - 1-arity: fun(Observe) -> ok - calls Observe(Value, Attrs) for each observation
Creates an ObservableGauge with a callback. Callback can be: - 0-arity: fun() -> number() - returns a single value - 1-arity: fun(Observe) -> ok - calls Observe(Value, Attrs) for each observation
Creates an ObservableUpDownCounter with a callback. Callback can be: - 0-arity: fun() -> number() - returns a single value - 1-arity: fun(Observe) -> ok - calls Observe(Value, Attrs) for each observation
Creates an UpDownCounter instrument.
Creates an UpDownCounter instrument with options.
Forces a flush of all pending metrics. This is a no-op in the current implementation.
Gets an instrument by name.
Gets or creates a Meter with the given name.
Gets or creates a Meter with the given name and options.
Lists all registered instruments.
Records a value in a Histogram.
Records a value in a Histogram with attributes.
Sets a value on a Gauge.
Sets a value on a Gauge with attributes.
Shuts down the MeterProvider. This is a no-op in the current implementation.
Unregisters all OTel instruments.
Unregisters an instrument by name. This removes the instrument from persistent_term, unregisters the underlying metric, and cleans up any associated vec metrics created for attributed operations.
Types
-type instrument() :: #otel_instrument{name :: binary(), kind :: counter | up_down_counter | histogram | gauge | observable_counter | observable_gauge | observable_up_down_counter, description :: binary() | undefined, unit :: binary() | undefined, meter :: #meter{name :: binary(), version :: binary() | undefined, schema_url :: binary() | undefined, resource :: #resource{attributes :: map(), schema_url :: binary() | undefined} | undefined} | undefined, handle :: term(), temporality :: cumulative | delta}.
Functions
-spec add(instrument(), number()) -> ok.
Adds a value to a Counter or UpDownCounter.
-spec add(instrument(), number(), map()) -> ok.
Adds a value to a Counter or UpDownCounter with attributes.
-spec collect_observables() -> ok.
Invokes all observable instrument callbacks. This should be called before metrics collection to update observable values.
-spec create_counter(meter(), binary() | atom()) -> instrument().
Creates a Counter instrument.
-spec create_counter(meter(), binary() | atom(), instrument_opts()) -> instrument().
Creates a Counter instrument with options.
-spec create_gauge(meter(), binary() | atom()) -> instrument().
Creates a Gauge instrument.
-spec create_gauge(meter(), binary() | atom(), instrument_opts()) -> instrument().
Creates a Gauge instrument with options.
-spec create_histogram(meter(), binary() | atom()) -> instrument().
Creates a Histogram instrument.
-spec create_histogram(meter(), binary() | atom(), instrument_opts()) -> instrument().
Creates a Histogram instrument with options.
-spec create_observable_counter(meter(), binary() | atom(), fun()) -> instrument().
Creates an ObservableCounter with a callback. Callback can be: - 0-arity: fun() -> number() - returns a single value - 1-arity: fun(Observe) -> ok - calls Observe(Value, Attrs) for each observation
-spec create_observable_gauge(meter(), binary() | atom(), fun()) -> instrument().
Creates an ObservableGauge with a callback. Callback can be: - 0-arity: fun() -> number() - returns a single value - 1-arity: fun(Observe) -> ok - calls Observe(Value, Attrs) for each observation
-spec create_observable_up_down_counter(meter(), binary() | atom(), fun()) -> instrument().
Creates an ObservableUpDownCounter with a callback. Callback can be: - 0-arity: fun() -> number() - returns a single value - 1-arity: fun(Observe) -> ok - calls Observe(Value, Attrs) for each observation
-spec create_up_down_counter(meter(), binary() | atom()) -> instrument().
Creates an UpDownCounter instrument.
-spec create_up_down_counter(meter(), binary() | atom(), instrument_opts()) -> instrument().
Creates an UpDownCounter instrument with options.
-spec force_flush() -> ok.
Forces a flush of all pending metrics. This is a no-op in the current implementation.
-spec get_instrument(binary() | atom()) -> instrument() | undefined.
Gets an instrument by name.
Gets or creates a Meter with the given name.
Gets or creates a Meter with the given name and options.
-spec list_instruments() -> [instrument()].
Lists all registered instruments.
-spec record(instrument(), number()) -> ok.
Records a value in a Histogram.
-spec record(instrument(), number(), map()) -> ok.
Records a value in a Histogram with attributes.
-spec set(instrument(), number()) -> ok.
Sets a value on a Gauge.
-spec set(instrument(), number(), map()) -> ok.
Sets a value on a Gauge with attributes.
-spec shutdown() -> ok.
Shuts down the MeterProvider. This is a no-op in the current implementation.
-spec unregister_all_instruments() -> ok.
Unregisters all OTel instruments.
Unregisters an instrument by name. This removes the instrument from persistent_term, unregisters the underlying metric, and cleans up any associated vec metrics created for attributed operations.