Documentation Index
Fetch the complete documentation index at: https://docs.tracectrl.ai/llms.txt
Use this file to discover all available pages before exploring further.
Overview
TraceCtrl uses Python’scontextvars to maintain a session ID per thread or async context. Session IDs are stored on a ContextVar named tracectrl_session_id, which means they are isolated per thread and per async task automatically.
Automatic Session IDs
The SDK generates a UUID session ID when you callnew_session():
TRACECTRL_SESSION_ID is set, new_session() uses that value instead of generating a UUID.
Manual Session IDs
Override with your own session ID — useful for tying traces to your application’s session concept:Environment Variable Override
SetTRACECTRL_SESSION_ID to force a specific session ID for any call to new_session():
set_session_id() ignores the env var — it always writes the value passed in.
API Reference
new_session() -> str
Generates a new session ID (or reads from TRACECTRL_SESSION_ID) and stores it in the current context. Returns the session ID.
current_session_id() -> str | None
Returns the current session ID, or None if new_session() or set_session_id() hasn’t been called yet in this context.
set_session_id(sid: str) -> None
Explicitly sets the session ID. Use this for cross-agent session propagation — when Agent B receives a session ID from Agent A, call set_session_id() to continue the session.
Multi-Agent Sessions
In a multi-agent system where agents communicate via HTTP, send the session ID in a custom header alongside the W3Ctraceparent:
X-TraceCtrl-Session header name is a TraceCtrl convention — pick anything you want as long as both sides agree, but stick with this name and the dashboard will recognise it.

