adk_trace_context (erlang_adk v0.7.0)

View Source

Strict W3C Trace Context parsing and propagation.

Trace identifiers are correlation data, never authorization data. Callers decide whether an inbound parent is trusted before passing the extracted context to an invocation. This module only validates and serializes the wire representation; it never changes a sampling policy implicitly.

Summary

Functions

Extract exactly one traceparent and at most one tracestate header.

Format a local or extracted context as a version-00 traceparent.

Inject traceparent/tracestate into a map or proplist of headers.

Parse the W3C version-00 traceparent representation.

Validate and canonicalize W3C tracestate. OWS around members is removed; member order is preserved because the left-most entry is special.

Types

trace_context/0

-type trace_context() ::
          #{trace_id := binary(),
            span_id := binary(),
            trace_flags := 0..255,
            remote => boolean(),
            tracestate => null | binary()}.

Functions

extract(Headers)

-spec extract(map() | list()) -> {ok, trace_context()} | {error, term()} | not_found.

Extract exactly one traceparent and at most one tracestate header.

format(Context)

-spec format(map()) -> {ok, binary()} | {error, term()}.

Format a local or extracted context as a version-00 traceparent.

inject(Context, Headers)

-spec inject(map(), map() | list()) -> {ok, map() | list()} | {error, term()}.

Inject traceparent/tracestate into a map or proplist of headers.

parse(_)

-spec parse(binary()) -> {ok, trace_context()} | {error, term()}.

Parse the W3C version-00 traceparent representation.

validate_span_id(Value)

-spec validate_span_id(term()) -> ok | {error, term()}.

validate_trace_id(Value)

-spec validate_trace_id(term()) -> ok | {error, term()}.

validate_tracestate(Value)

-spec validate_tracestate(term()) -> {ok, null | binary()} | {error, term()}.

Validate and canonicalize W3C tracestate. OWS around members is removed; member order is preserved because the left-most entry is special.