View Source Datadog.DataStreams.Propagator (Data Streams Ex v1.1.0)

Handles propagating Datadog.DataStreams.Pathway via encoding and adding to message headers.

Link to this section Summary

Functions

Tries to decode a value into a pathway.

Decodes a pathway from a list or map of headers. If no matching header, or if the header is invalid, nil is returned.

Tries to decode a Base64 encoded value into a pathway.

Decodes a pathway binary time from zigzag encoding.

Encodes a pathway to a string able to be placed in a header.

Encodes a pathway into a list or map of headers.

Encodes a pathway to a string able to be placed in a header.

Encodes a pathway time using zigzag encoding.

Returns the well known header key for propagating encoded pathway data.

Returns the well known base64 encoded header key for propagating encoded pathway data.

Link to this section Functions

@spec decode(binary()) :: Datadog.DataStreams.Pathway.t() | nil

Tries to decode a value into a pathway.

examples

Examples

# Verified from golang implementation
iex> Propagator.decode(<<174, 208, 17, 141, 62, 199, 215, 238, 224, 159, 240, 170, 211, 97, 224, 159, 240, 170, 211, 97>>)
%Pathway{hash: 17210443572488294574, pathway_start: 1677632342000000000, edge_start: 1677632342000000000}

iex> Propagator.decode("invalid")
nil
@spec decode_header([{binary(), binary()}] | %{required(binary()) => binary()} | nil) ::
  Datadog.DataStreams.Pathway.t() | nil

Decodes a pathway from a list or map of headers. If no matching header, or if the header is invalid, nil is returned.

examples

Examples

iex> Propagator.decode_header([{"dd-pathway-ctx-base64", "rtARjT7H1+7gn/Cq02Hgn/Cq02E="}])
%Pathway{hash: 17210443572488294574, pathway_start: 1677632342000000000, edge_start: 1677632342000000000}

iex> Propagator.decode_header(%{"dd-pathway-ctx" => <<174, 208, 17, 141, 62, 199, 215, 238, 224, 159, 240, 170, 211, 97, 224, 159, 240, 170, 211, 97>>})
%Pathway{hash: 17210443572488294574, pathway_start: 1677632342000000000, edge_start: 1677632342000000000}

iex> Propagator.decode_header(%{"content-type" => "application-json"})
nil
@spec decode_str(String.t()) :: Datadog.DataStreams.Pathway.t() | nil

Tries to decode a Base64 encoded value into a pathway.

examples

Examples

# Verified from golang implementation
iex> Propagator.decode_str("rtARjT7H1+7gn/Cq02Hgn/Cq02E=")
%Pathway{hash: 17210443572488294574, pathway_start: 1677632342000000000, edge_start: 1677632342000000000}

iex> Propagator.decode_str("invalid")
nil
@spec decode_time(binary()) :: non_neg_integer() | nil

Decodes a pathway binary time from zigzag encoding.

examples

Examples

# Verified from golang implementation
iex> Propagator.decode_time(<<224, 159, 240, 170, 211, 97>>)
1677632342000000000

iex> Propagator.decode_time(<<1, 2, 3, 4>>)
nil
@spec encode(Datadog.DataStreams.Pathway.t()) :: binary()

Encodes a pathway to a string able to be placed in a header.

examples

Examples

# Verified from golang implementation
iex> Propagator.encode(%Pathway{hash: 17210443572488294574, pathway_start: 1677632342000000000, edge_start: 1677632342000000000})
<<174, 208, 17, 141, 62, 199, 215, 238, 224, 159, 240, 170, 211, 97, 224, 159, 240, 170, 211, 97>>

# Verified from golang implementation
iex> Propagator.encode(%Pathway{hash: 2003974475228685984, pathway_start: 1677628446000000000, edge_start: 1677628446000000000})
<<160, 166, 244, 238, 42, 140, 207, 27, 224, 212, 148, 167, 211, 97, 224, 212, 148, 167, 211, 97>>
Link to this function

encode_header(headers, pathway)

View Source
@spec encode_header(headers, Datadog.DataStreams.Pathway.t()) :: headers
when headers: [{binary(), binary()}] | %{required(binary()) => binary()} | nil

Encodes a pathway into a list or map of headers.

examples

Examples

iex> Propagator.encode_header([], %Pathway{hash: 17210443572488294574, pathway_start: 1677632342000000000, edge_start: 1677632342000000000})
[{"dd-pathway-ctx", <<174, 208, 17, 141, 62, 199, 215, 238, 224, 159, 240, 170, 211, 97, 224, 159, 240, 170, 211, 97>>}]

iex> Propagator.encode_header(%{}, %Pathway{hash: 17210443572488294574, pathway_start: 1677632342000000000, edge_start: 1677632342000000000})
%{"dd-pathway-ctx" => <<174, 208, 17, 141, 62, 199, 215, 238, 224, 159, 240, 170, 211, 97, 224, 159, 240, 170, 211, 97>>}
@spec encode_str(Datadog.DataStreams.Pathway.t()) :: String.t()

Encodes a pathway to a string able to be placed in a header.

examples

Examples

# Verified from golang implementation
iex> Propagator.encode_str(%Pathway{hash: 17210443572488294574, pathway_start: 1677632342000000000, edge_start: 1677632342000000000})
"rtARjT7H1+7gn/Cq02Hgn/Cq02E="

# Verified from golang implementation
iex> Propagator.encode_str(%Pathway{hash: 2003974475228685984, pathway_start: 1677628446000000000, edge_start: 1677628446000000000})
"oKb07iqMzxvg1JSn02Hg1JSn02E="
@spec encode_time(non_neg_integer()) :: binary()

Encodes a pathway time using zigzag encoding.

examples

Examples

# Verified from golang implementation
iex> Propagator.encode_time(1677632342000000000)
<<224, 159, 240, 170, 211, 97>>
@spec propagation_key() :: String.t()

Returns the well known header key for propagating encoded pathway data.

examples

Examples

iex> Propagator.propagation_key()
"dd-pathway-ctx"
Link to this function

propagation_key_base64()

View Source
@spec propagation_key_base64() :: String.t()

Returns the well known base64 encoded header key for propagating encoded pathway data.

examples

Examples

iex> Propagator.propagation_key_base64()
"dd-pathway-ctx-base64"