Expand description
W3C trace context, and the request identifier that travels beside it.
A request that arrives with a traceparent header is part of a trace
somebody else started: a gateway, a client library, another service. Its
trace id is kept so the lines this server logs – and, once spans are
exported, the spans themselves – join that trace rather than starting an
unrelated one. A request without one starts a trace of its own.
Hand-written rather than taken from the opentelemetry crates, which this
side does not otherwise need: parsing traceparent is a fixed-width format
of four fields, and the rules for refusing one are short enough to read
here. See https://www.w3.org/TR/trace-context/.
Nothing here generates an identifier. That needs randomness, and where it comes from is a host’s business – the server has a thread to keep a generator on, a Cloudflare Worker has the JavaScript runtime’s. So this module only parses, validates and formats, and builds on wasm32 as it does everywhere else.
Structs§
- SpanId
- A span id: eight bytes, never all zero. Here, the id of the caller’s span that this request is a child of.
- Trace
Context - The trace a request belongs to.
- TraceId
- A trace id: sixteen bytes, never all zero.
Constants§
- MAX_
REQUEST_ ID_ LEN - The longest
x-request-idtaken from a client. Long enough for any identifier scheme in use – a UUID is 36, a ULID 26, a Heroku or Envoy id well under this – and short enough that the header cannot be used to make every log line carry a payload.
Functions§
- parse_
traceparent - Parse a
traceparentvalue:version-traceid-parentid-flags, as lowercase hex. - valid_
request_ id - Whether a client’s
x-request-idcan be used as given: between one andMAX_REQUEST_ID_LENbytes, every one of them visible ASCII.