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

Returns the count of dropped attributes in the given 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

Returns the count of dropped attributes in the given Attributes.
Link to this function

is_valid_attribute(Key, Value)

View Source
-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">>}
Link to this function

new(Pairs, CountLimit, ValueLengthLimit)

View Source
-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.
Link to this function

set(NewListOrMap, Attributes)

View Source
-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.
Link to this function

set(Key, Value, Attributes)

View Source

Sets the given key-value pair in the given Attributes.

Overrides the existing value under Key if Key already exists. Returns the updated Attributes.