Skip to main content

Module trace

Module trace 

Source
Expand description

Distributed-tracing span context and propagation codecs.

Shared by the tracing plugins (opentelemetry, zipkin, skywalking), which are each a start/end node pair around upstream: the start node extracts or creates a SpanContext, stores it in context.message (per-request state), and injects the downstream propagation header so the upstream service continues the trace; the end node loads the span, computes its duration, and exports it to the collector (fire-and-forget).

Provides trace/span id generation and codecs for the three wire formats: W3C traceparent (OpenTelemetry), B3 (Zipkin), and SkyWalking sw8.

Structs§

SpanContext
A span in flight: the trace it belongs to, this hop’s span, its parent, the sampling decision, and when it started (unix millis).

Constants§

SPAN_KEY
The reserved context.message key under which the active span is stored.

Functions§

build_b3_headers
Builds the B3 multi-headers for a span as (name, value) pairs to set on the outgoing request.
build_traceparent
Builds a W3C traceparent header value for a span.
hex 🔒
load_span
Loads the span previously stored by the start node.
new_span_id
A random 16-hex-char (64-bit) span id.
new_trace_id
A random 32-hex-char (128-bit) trace id.
now_ms
Current unix time in milliseconds.
parse_b3
Parses B3 propagation from either the single b3 header (trace-span-sampled-parent) or the multi-header form, given a lookup of the relevant request headers, into (trace_id, parent_span_id, sampled).
parse_sw8
Parses a SkyWalking sw8 header (hyphen-separated, base64 fields) into (trace_id, parent_segment_span_id, sampled). Field 0 is the sample flag, field 1 the base64 trace id, field 3 the parent span id.
parse_traceparent
Parses a W3C traceparent header (00-<trace>-<parent>-<flags>) into (trace_id, parent_span_id, sampled).
store_span
Stores the span in context.message.
sw8_encode
Base64-encodes a field for an sw8 header.