otel_attributes (OpenTelemetry API v1.4.0)

View Source

Functions to work with Attributes.

An Attribute is a key-value pair with string or atom keys. See the specification.

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.

Types

t/0

-type t() ::
          #attributes{count_limit :: integer(),
                      value_length_limit :: integer() | infinity,
                      dropped :: integer(),
                      map :: map()}.

Functions

dropped(Attributes)

Returns the count of dropped attributes in the given Attributes.

is_valid_attribute(Key, Value)

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

map(Attributes)

-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">>}

new(Pairs, CountLimit, ValueLengthLimit)

-spec new([opentelemetry:attribute()] | opentelemetry:attributes_map(), 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.

set(NewListOrMap, Attributes)

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.

set(Key, Value, Attributes)

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

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