Skip to main content
Set user_id on a trace to associate it with a specific user — enabling per-user filtering, cost tracking, and analytics in the dashboard.
TraceRoot dashboard showing traces filtered by user

Using context manager

Use using_attributes to propagate user_id to all traces within a block:
from traceroot import using_attributes

with using_attributes(user_id="user-42"):
    response = agent.run("What's the weather in SF?")

Using decorator / inside a function

Call update_current_trace from within any observed function:
from traceroot import observe, update_current_trace

@observe(name="handle_request", type="agent")
def handle_request(query: str, user_id: str):
    update_current_trace(user_id=user_id)
    return process(query)