W3C Trace Context codec (https://www.w3.org/TR/trace-context/), pure.
STD-04 O1: trace context crosses hops as a W3C traceparent
(MCP params._meta.traceparent per SEP-414, NATS header traceparent,
child env TRACEPARENT). This ns only parses, formats and derives
contexts; it performs no I/O and owns no randomness — every fn that
needs fresh ids takes the random source as an argument.
Context value: {:version "00" :trace-id 32 lower-hex chars, not all zero :parent-id 16 lower-hex chars, not all zero :flags 2 lower-hex chars (bit 0 = sampled) :tracestate ["k=v" ...]} ; optional, opaque members, at most 32
Only version 00 is accepted; version ff is invalid by the spec and any
other version is refused rather than parsed by the forward-compat rule.
tracestate members are kept opaque: they are split on commas, trimmed
of optional white space, empty members dropped, and otherwise passed
through unchanged. A header of more than 32 members is discarded whole.
W3C Trace Context codec (https://www.w3.org/TR/trace-context/), pure.
STD-04 O1: trace context crosses hops as a W3C `traceparent`
(MCP params._meta.traceparent per SEP-414, NATS header `traceparent`,
child env TRACEPARENT). This ns only parses, formats and derives
contexts; it performs no I/O and owns no randomness — every fn that
needs fresh ids takes the random source as an argument.
Context value:
{:version "00"
:trace-id 32 lower-hex chars, not all zero
:parent-id 16 lower-hex chars, not all zero
:flags 2 lower-hex chars (bit 0 = sampled)
:tracestate ["k=v" ...]} ; optional, opaque members, at most 32
Only version 00 is accepted; version ff is invalid by the spec and any
other version is refused rather than parsed by the forward-compat rule.
`tracestate` members are kept opaque: they are split on commas, trimmed
of optional white space, empty members dropped, and otherwise passed
through unchanged. A header of more than 32 members is discarded whole.(->headers ctx)Header map {"traceparent" .. "tracestate" ..} for a valid context; tracestate is omitted when empty. nil for an invalid context.
Header map {"traceparent" .. "tracestate" ..} for a valid context;
tracestate is omitted when empty. nil for an invalid context.(<-headers headers)Context from a header map. Keys are matched case-insensitively (HTTP header names are case-insensitive) and may be strings or keywords.
Context from a header map. Keys are matched case-insensitively (HTTP header names are case-insensitive) and may be strings or keywords.
(child ctx new-span-id)Context for a hop below ctx: same trace-id, flags and tracestate,
parent-id replaced by new-span-id (the id of the span the caller
opened). nil when ctx is invalid or new-span-id is not a valid
span id.
Context for a hop below `ctx`: same trace-id, flags and tracestate, parent-id replaced by `new-span-id` (the id of the span the caller opened). nil when `ctx` is invalid or `new-span-id` is not a valid span id.
(flags? s)True iff s is 2 lower-hex chars.
True iff `s` is 2 lower-hex chars.
(format-traceparent {:keys [trace-id parent-id flags] :as ctx})Format a context as a traceparent header value. Returns nil when the context is not valid (never emits a header a parser would refuse).
Format a context as a traceparent header value. Returns nil when the context is not valid (never emits a header a parser would refuse).
(format-tracestate members)Join opaque tracestate members into a header value. Returns nil for an empty or absent list, or when there are more than 32 members.
Join opaque tracestate members into a header value. Returns nil for an empty or absent list, or when there are more than 32 members.
(new-root random-fn)(new-root random-fn flags)A new root context: fresh trace-id and parent-id from random-fn,
flags default "01" (sampled), no tracestate. nil when the source
cannot produce non-zero ids.
A new root context: fresh trace-id and parent-id from `random-fn`, flags default "01" (sampled), no tracestate. nil when the source cannot produce non-zero ids.
(new-span-id random-fn)Fresh 16-hex span id from random-fn, or nil if the source yields only
zero ids.
Fresh 16-hex span id from `random-fn`, or nil if the source yields only zero ids.
(new-trace-id random-fn)Fresh 32-hex trace id from random-fn, or nil if the source yields
only zero ids.
Fresh 32-hex trace id from `random-fn`, or nil if the source yields only zero ids.
(parse traceparent)(parse traceparent tracestate)Parse a traceparent value and an optional tracestate value into one context. nil when traceparent is invalid. An invalid tracestate is dropped; it never invalidates the traceparent.
Parse a traceparent value and an optional tracestate value into one context. nil when traceparent is invalid. An invalid tracestate is dropped; it never invalidates the traceparent.
(parse-traceparent s)Parse a traceparent header value. Returns a context map (without :tracestate) or nil when the value is not a valid version-00 header: wrong length, upper-case hex, all-zero trace-id or parent-id, version ff or any version other than 00.
Parse a traceparent header value. Returns a context map (without :tracestate) or nil when the value is not a valid version-00 header: wrong length, upper-case hex, all-zero trace-id or parent-id, version ff or any version other than 00.
(parse-tracestate s)Split a tracestate header value into its opaque members. Returns a vector (possibly empty) or nil when the value is absent or carries more than 32 members (the whole header is discarded, as the spec allows).
Split a tracestate header value into its opaque members. Returns a vector (possibly empty) or nil when the value is absent or carries more than 32 members (the whole header is discarded, as the spec allows).
(random-hex random-fn n-bytes)Lower-hex string of n-bytes bytes drawn from random-fn, a fn of no
arguments returning an integer (only its low 8 bits are used).
Lower-hex string of `n-bytes` bytes drawn from `random-fn`, a fn of no arguments returning an integer (only its low 8 bits are used).
(sampled? {:keys [flags]})True iff the sampled bit (0x01) of the context's flags is set.
True iff the sampled bit (0x01) of the context's flags is set.
(secure-random-fn)A random-fn backed by one java.security.SecureRandom. Convenience for callers; nothing in this ns calls it implicitly.
A random-fn backed by one java.security.SecureRandom. Convenience for callers; nothing in this ns calls it implicitly.
(span-id? s)True iff s is 16 lower-hex chars and not all zero (a valid parent-id).
True iff `s` is 16 lower-hex chars and not all zero (a valid parent-id).
(trace-id? s)True iff s is 32 lower-hex chars and not all zero.
True iff `s` is 32 lower-hex chars and not all zero.
(valid? {:keys [version trace-id parent-id flags tracestate] :as ctx})True iff ctx is a well-formed version-00 context.
True iff `ctx` is a well-formed version-00 context.
cljdoc builds & hosts documentation for Clojure/Script libraries
| Ctrl+k | Jump to recent docs |
| ← | Move to previous article |
| → | Move to next article |
| Ctrl+/ | Jump to the search field |