Skip to main content
Correlation-ID context propagation for the SDK pipeline. Carries lightweight, thread- and task-local context (a trace_id for a whole run, plus run_id, slide_id, and the current pipeline stage) down the execution chain without threading parameters through every function. Structured logging reads this context so every log line is automatically tagged with run -> slide -> request correlation fields. The context lives in a single contextvars.ContextVar, so it is isolated per thread and per asyncio task. That makes it safe under the SDK’s ThreadPoolExecutor fan-out (one slide per worker) and its asyncio tile dispatch (one task per request).

new_trace_id

Generates a new, time-sortable correlation ID. Produces a 26-character ULID-style identifier: a 48-bit millisecond timestamp followed by 80 bits of randomness, encoded with Crockford base32. The leading timestamp makes IDs lexicographically sortable by creation time. Returns: A 26-character uppercase Crockford base32 string.

get_context

Returns a copy of the currently bound correlation context. Returns: A mapping of the bound context fields (for example trace_id, run_id, slide_id, stage). Empty when nothing is bound.

bind_context

Binds correlation fields for the duration of the with block. Merges the given fields onto the current context, yields, then restores the previous context on exit (including on error). Fields whose value is None are ignored, which makes optional binding ergonomic.
Correlation fields to bind, for example trace_id, run_id, slide_id, or stage.
Returns: A context manager that yields None; the merged context is active only inside the with block and is restored on exit.