Documentation Index
Fetch the complete documentation index at: https://docs.svantic.com/llms.txt
Use this file to discover all available pages before exploring further.
Trace propagation
What it is
A small set of pure functions for working with W3C Trace Context. Svantic embeds atraceparent (and optionally baggage) in every dispatch so your agent’s spans connect back to the caller’s trace tree. The SDK already parses those headers for you and surfaces the parent trace-id and span-id on CapabilitySessionContext, so you normally don’t need these helpers.
You import them only when you need to do one of three things:
- Forward the trace downstream — you’re calling a non-Svantic service (REST, gRPC) from inside a capability and want the same trace tree to span both hops.
- Inspect trace context in custom transports — you’re writing your own dispatch path and need to extract trace fields from a raw payload.
- Read baggage — you want tenant or user context the upstream caller attached.
When to use it
- Forwarding trace context to an outbound
fetch/ HTTP client. - Building a custom exporter or middleware that reads upstream trace fields.
- Writing tests that assert trace context was wired through.
ctx.trace_id / ctx.parent_span_id on the session context, you can ignore this module entirely.
Functional usage
parse_traceparent(raw)
traceparent header. Returns null if the header is missing, malformed, or uses an unsupported version — never throws.
Only version 00 is accepted. All-zero trace-ids and span-ids are rejected per spec.
ParsedTraceparent
| Field | Type | Description |
|---|---|---|
version | string | Always '00'. |
trace_id | string | 32-hex lowercase. |
parent_span_id | string | 16-hex lowercase. |
flags | string | 2-hex lowercase. |
sampled | boolean | true iff the sampled flag (bit 0) is set. |
parse_baggage(raw)
baggage header into a plain map. Malformed entries are skipped silently (per spec). Values are percent-decoded. Always returns an object — never null — so callers can unconditionally spread it.
extract_trace_context(session)
session blob. Returns null when the session has no propagation_headers. Never throws — bad headers simply produce missing fields on the result.
ExtractedTraceContext
| Field | Type | Description |
|---|---|---|
propagation_headers | Record<string, string> | Raw headers as sent by the mesh. Forward verbatim to downstream HTTP services. |
parent_trace_id? | string | From traceparent, when valid. |
parent_span_id? | string | From traceparent, when valid. |
baggage | Record<string, string> | Parsed baggage map. Empty object when absent or unparseable. |
