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
get_context
trace_id,
run_id, slide_id, stage). Empty when nothing is bound.
bind_context
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.None; the merged context is active
only inside the with block and is restored on exit.
