Context API Reference¶
Request-scoped context and correlation IDs.
Request-scoped context for correlation IDs and metadata.
RequestContext
dataclass
¶
Per-request context propagated through middleware and handlers.
Source code in src/istos/context.py
token
property
¶
The auth token from the request attachment (envelope-aware).
RequestEnvelope
dataclass
¶
Auth token (+ optional correlation/trace) carried in the Zenoh attachment.
A bare UTF-8 string is still just a token — old clients keep working. When
you also need correlation_id or traceparent, we send compact JSON::
{"tok": "...", "cid": "...", "tp": "..."}
Source code in src/istos/context.py
get_request_context()
¶
Return the current request context, creating one if absent.
ingress_context(*, prefix, operation, attachment, principal=None)
¶
A fresh context for one delivery.
The correlation id and traceparent come from the envelope only when they
pass :func:sanitize_correlation_id / :func:sanitize_traceparent. Otherwise
the id is a new UUID and the traceparent is absent — a reused task must not
keep the previous delivery's values.
Source code in src/istos/context.py
peek_request_context()
¶
Return the active request context without creating one.
Used by outbound calls to propagate metadata (correlation_id, traceparent) only when they originate inside a request — a root call carries nothing.
Source code in src/istos/context.py
pop_request_context(token)
¶
push_request_context(ctx)
¶
reset_request_context()
¶
sanitize_correlation_id(value)
¶
A caller-supplied correlation id, or None when it is missing or unsafe.
Unsafe means empty, too long, or containing a control character, quote, or backslash — those are the characters that break a log line or a label.
Source code in src/istos/context.py
sanitize_traceparent(value)
¶
A caller-supplied W3C traceparent, or None when it is not one.
The all-zero trace id and span id are invalid per the spec and are rejected so a peer cannot pin every span to a single forged trace.