instrument_exemplar (instrument v1.0.0)

View Source

Exemplar reservoir sampling for metrics.

Implements fixed-size reservoir sampling for collecting exemplars with trace context per OTel spec. Default reservoir size is 4.

Exemplars capture representative observations with their trace context, allowing correlation between metrics and traces.

Summary

Functions

Collects all exemplars from the reservoir.

Collects all exemplars from the reservoir identified by reference.

Deletes the reservoir identified by reference. Safe to call with undefined or a reference that is no longer present.

Initialize the ETS table for exemplar storage. Called during application startup.

Creates a new exemplar reservoir with default size (4).

Creates a new exemplar reservoir with specified size.

Creates a new reservoir with default size and returns a reference key.

Creates a new reservoir with specified size and returns a reference key.

Offers a value to the reservoir with automatic trace context capture. Uses reservoir sampling to maintain a fixed-size sample.

Offers a value to the reservoir with explicit trace context.

Offers a value to the reservoir identified by reference.

Resets the reservoir, clearing all exemplars.

Resets the reservoir identified by reference.

Types

reservoir/0

-opaque reservoir()

Functions

collect(Reservoir)

-spec collect(reservoir()) ->
                 [#exemplar{filtered_attributes :: map(),
                            value :: number(),
                            timestamp :: integer(),
                            span_id :: <<_:64>> | undefined,
                            trace_id :: <<_:128>> | undefined}].

Collects all exemplars from the reservoir.

collect_ref(Ref)

-spec collect_ref(reference() | undefined) ->
                     [#exemplar{filtered_attributes :: map(),
                                value :: number(),
                                timestamp :: integer(),
                                span_id :: <<_:64>> | undefined,
                                trace_id :: <<_:128>> | undefined}].

Collects all exemplars from the reservoir identified by reference.

delete_reservoir(Ref)

-spec delete_reservoir(reference() | undefined) -> ok.

Deletes the reservoir identified by reference. Safe to call with undefined or a reference that is no longer present.

init_table()

-spec init_table() -> ok.

Initialize the ETS table for exemplar storage. Called during application startup.

new_reservoir()

-spec new_reservoir() -> reservoir().

Creates a new exemplar reservoir with default size (4).

new_reservoir(Size)

-spec new_reservoir(pos_integer()) -> reservoir().

Creates a new exemplar reservoir with specified size.

new_reservoir_ref()

-spec new_reservoir_ref() -> reference().

Creates a new reservoir with default size and returns a reference key.

new_reservoir_ref(Size)

-spec new_reservoir_ref(pos_integer()) -> reference().

Creates a new reservoir with specified size and returns a reference key.

offer(Reservoir, Value, FilteredAttributes)

-spec offer(reservoir(), number(), map()) -> reservoir().

Offers a value to the reservoir with automatic trace context capture. Uses reservoir sampling to maintain a fixed-size sample.

offer(Reservoir, Value, FilteredAttrs, _)

-spec offer(reservoir(), number(), map(), {binary() | undefined, binary() | undefined}) -> reservoir().

Offers a value to the reservoir with explicit trace context.

offer_ref(Ref, Value, FilteredAttributes)

-spec offer_ref(reference(), number(), map()) -> ok.

Offers a value to the reservoir identified by reference.

reset(Reservoir)

-spec reset(reservoir()) -> reservoir().

Resets the reservoir, clearing all exemplars.

reset_ref(Ref)

-spec reset_ref(reference()) -> ok.

Resets the reservoir identified by reference.