Anatomy of a traceparent
Quick Start
Functions
make()
Makes a new Traceparent which one can thentoString() to get the value.
By default the flags are both sampled (FLAG_SAMPLE) and randomed (FLAG_RANDOM).
A new Traceparent instance with randomly generated trace-id and parent-id
parse(value)
Allows you to parse an incoming value into the areas, easy for a server to continue the trace chain.The traceparent header value to parse
A Traceparent instance if parsing succeeds, or null if the value is invalid
sample(id)
Modifies the flags of a Traceparent to sample the traceparent flag bit.The Traceparent instance to modify
You may wish to
.child() before you sample, as is required by the specunsample(id)
Modifies the flags of a Traceparent to unsample the traceparent flag bit.The Traceparent instance to modify
You may wish to
.child() before you unsample, as is required by the specis_sampled(id)
Returns if the traceparent is currently being sampled.The Traceparent instance to check
True if the sampled flag bit is set, false otherwise
is_randomed(id)
Returns if the traceparent is currently random.The Traceparent instance to check
True if the random flag bit is set, false otherwise
Constants
FLAG_SAMPLE
The bitmask representing a sampled traceparent.FLAG_RANDOM
The bitmask representing a random traceparent.Types
Traceparent
The Traceparent type represents a W3C Trace Context traceparent header.The version of the traceparent (always “00” for current implementation)
The trace ID (32 hexadecimal characters)
The parent ID (16 hexadecimal characters)
The flags byte as a number (0-255)
child()
Branches the traceparent into a new child, creating a new parent_id. All existing flags are copied over.A new Traceparent with the same trace_id and flags, but a new parent_id
toString()
Converts the Traceparent to its string representation for use in HTTP headers.The formatted traceparent string (e.g., “00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01”)