View Source Datadog.DataStreams.Tags (Data Streams Ex v1.2.2)

A helper module to enumerate and filter over data stream tags.

Summary

Types

An encoded list of tags. This is the format that Datadog expects when we send data. It's a list of key value binary joined via :. For example: "partition:1", "group:some-consumer-group", "topic:a-topic".

All allowed tag input types. This could be any one of the following examples

t()

The type all tags are internally mapped to.

Functions

Tags a list of tags and converts them to a list of binary tags. This is the format that Datadog expects. This also orders the tags to ensure it matches other languages when hashing.

Filters a list of tags to a known list of allowed tags. This varies based on the context of where it is used.

Parses any type of tag input and normalizes it to our internal t:t type. Note this will also filter out invalid data like nil values.

Types

@type encoded() :: [binary()]

An encoded list of tags. This is the format that Datadog expects when we send data. It's a list of key value binary joined via :. For example: "partition:1", "group:some-consumer-group", "topic:a-topic".

@type input() ::
  [{binary() | atom(), binary()}]
  | %{required(binary() | atom()) => binary()}
  | [binary()]

All allowed tag input types. This could be any one of the following examples:

[{:key, "value"}, {:key_two, "value_two"}]
[{"key", "value"}, {"key_two", "value_two"}]
%{key: "value", key_two: "value_two"}
%{"key" => "value", "key_two" => "value_two"}
["key:value", "key_two:value_two"]
@type t() :: [{binary(), binary()}]

The type all tags are internally mapped to.

Functions

@spec encode(t()) :: [binary()]

Tags a list of tags and converts them to a list of binary tags. This is the format that Datadog expects. This also orders the tags to ensure it matches other languages when hashing.

Examples

iex> Tags.encode([{"tag_two", "value_two"}, {"tag", "value"}])
["tag:value", "tag_two:value_two"]
@spec filter(t(), atom()) :: t()

Filters a list of tags to a known list of allowed tags. This varies based on the context of where it is used.

Examples

iex> [{"key", "value"}, {"topic", "one"}, {"key_two", "value_two"}]
...> |> Tags.filter(:hash)
[{"topic", "one"}]
@spec parse(input()) :: t()

Parses any type of tag input and normalizes it to our internal t:t type. Note this will also filter out invalid data like nil values.

Examples

iex> [{:key, "value"}, {:key_two, "value_two"}]
...> |> Tags.parse()
[{"key", "value"}, {"key_two", "value_two"}]

iex> [{"key", "value"}, {"key_two", "value_two"}]
...> |> Tags.parse()
[{"key", "value"}, {"key_two", "value_two"}]

iex> %{key: "value", key_two: "value_two"}
...> |> Tags.parse()
[{"key", "value"}, {"key_two", "value_two"}]

iex> %{"key" => "value", "key_two" => "value_two"}
...> |> Tags.parse()
[{"key", "value"}, {"key_two", "value_two"}]

iex> ["key:value", "key_two:value_two"]
...> |> Tags.parse()
[{"key", "value"}, {"key_two", "value_two"}]

iex> [{"key", nil}, {"key_two", "value_two"}]
...> |> Tags.parse()
[{"key_two", "value_two"}]