View Source otel_attributes (opentelemetry_api v1.3.0)
Functions to work with Attributes.
An Attribute is a key-value pair with string or atom keys. See the specification.Link to this section Summary
Functions
Attributes
.Checks whether the given key-value pair makes for a valid attribute.
Returns the Attributes in the form of a map.
Creates a new Attributes
from Pairs
with the given count and value length limits.
Sets the given key-value pairs in the given Attributes
. Overrides the existing value for a given key if it already exists in Attributes
.
Sets the given key-value pair in the given Attributes
.
Link to this section Types
-type t() :: #attributes{}.
Link to this section Functions
Attributes
.
-spec is_valid_attribute(opentelemetry:attribute_key(), opentelemetry:attribute_value()) -> boolean().
Checks whether the given key-value pair makes for a valid attribute.
For example: otel_attributes:is_valid_attribute(<<"key">>, <<"value">>).
%=> true
otel_attributes:is_valid_attribute(atom_key, <<"value">>).
%=> true
otel_attributes:is_valid_attribute(123, <<"value">>).
%=> false
-spec map(t()) -> map().
Returns the Attributes in the form of a map.
For example: otel_attributes:new([], 10, 10),
otel_attributes:set(<<"key">>, <<"value">>, Attributes),
otel_attributes:map(Attributes).
%=> #{<<"key">> => <<"value">>}
-spec new([opentelemetry:attribute()] | opentelemetry:attributes_map() | term(), integer(), integer() | infinity) -> t().
Creates a new Attributes
from Pairs
with the given count and value length limits.
Pairs
can be a list of key-value pairs or a map. If Pairs
is not a list or map, the function returns an empty Attributes
.
-spec set([opentelemetry:attribute()] | opentelemetry:attributes_map() | term(), t()) -> t().
Sets the given key-value pairs in the given Attributes
. Overrides the existing value for a given key if it already exists in Attributes
.
NewListOrMap
can be a list of key-value pairs or a map. If NewListOrMap
is not a list or map, the function returns Attributes
as is. Returns the updated Attributes
.
-spec set(opentelemetry:attribute_key(), opentelemetry:attribute_value(), t()) -> t().
Sets the given key-value pair in the given Attributes
.
Key
if Key
already exists. Returns the updated Attributes
.