instrument_attributes (instrument v1.0.0)
View SourceAttribute handling for OpenTelemetry-compatible instrumentation.
Attributes are key-value pairs used for dimensions in metrics and metadata in traces. Keys must be atoms or binaries, values can be binaries, integers, floats, or booleans.
Summary
Functions
Apply OTel attribute limits: cap the count, truncate string values. Returns {LimitedAttrs, DroppedCount}. Existing keys in Existing are preserved unconditionally; new keys are added until CountLimit is hit. Use unlimited for either limit to skip that check.
Three-arity form for limiting an addition to an existing attribute map. Useful when merging into a span's existing attributes.
Creates attributes from a list of {key, value} pairs.
Gets a value from the attributes.
Gets a value from the attributes with a default.
Computes a hash of the attributes for use as map keys.
Merges two attribute sets. Values in the second set override the first.
Creates a new empty attribute set.
Creates an attribute set from a map or proplist.
Puts a key-value pair into the attributes.
Removes a key from the attributes.
Extracts label values in order matching the given label keys. This is used for compatibility with the existing vector metrics.
Converts attributes to a list of {key, value} pairs.
Truncate a single attribute value to the given length limit. Strings/binaries longer than the limit are truncated. Lists are truncated element by element. Numeric, boolean, and atom values are returned unchanged. unlimited is a no-op.
Validates all attributes in the set. Returns {ok, Attrs} if valid, {error, Reason} if not.
Types
Functions
-spec apply_limits(map(), map() | pos_integer() | unlimited) -> {map(), non_neg_integer()}.
Apply OTel attribute limits: cap the count, truncate string values. Returns {LimitedAttrs, DroppedCount}. Existing keys in Existing are preserved unconditionally; new keys are added until CountLimit is hit. Use unlimited for either limit to skip that check.
Equivalent to apply_limits(Existing, NewAttrs, CountLimit) with the configured value-length limit applied automatically.
-spec apply_limits(map(), map(), pos_integer() | unlimited) -> {map(), non_neg_integer()}.
Three-arity form for limiting an addition to an existing attribute map. Useful when merging into a span's existing attributes.
Creates attributes from a list of {key, value} pairs.
-spec get(t(), attribute_key()) -> attribute_value() | undefined.
Gets a value from the attributes.
-spec get(t(), attribute_key(), term()) -> attribute_value() | term().
Gets a value from the attributes with a default.
Computes a hash of the attributes for use as map keys.
Merges two attribute sets. Values in the second set override the first.
-spec new() -> t().
Creates a new empty attribute set.
Creates an attribute set from a map or proplist.
-spec put(t(), attribute_key(), attribute_value()) -> t().
Puts a key-value pair into the attributes.
-spec remove(t(), attribute_key()) -> t().
Removes a key from the attributes.
-spec to_label_values(t(), [attribute_key()]) -> [binary()].
Extracts label values in order matching the given label keys. This is used for compatibility with the existing vector metrics.
-spec to_list(t()) -> [{attribute_key(), attribute_value()}].
Converts attributes to a list of {key, value} pairs.
-spec truncate_value(term(), pos_integer() | unlimited) -> term().
Truncate a single attribute value to the given length limit. Strings/binaries longer than the limit are truncated. Lists are truncated element by element. Numeric, boolean, and atom values are returned unchanged. unlimited is a no-op.
Validates all attributes in the set. Returns {ok, Attrs} if valid, {error, Reason} if not.