Documentation Index
Fetch the complete documentation index at: https://mintlify.com/sidmanale643/northstar/llms.txt
Use this file to discover all available pages before exploring further.
northstar.trace() marks the outermost boundary of a single agent invocation, creating a Run record in NorthStar. Every span, event, metric, and log call made while the trace is active is associated with that run. The function works in two forms: as a decorator (applied to a function) and as a context manager (used with with). Both forms automatically capture inputs, outputs, latency, and exceptions, and both support async functions.
Function signature
Parameters
Display name for this run in the NorthStar dashboard. When used as a decorator and
name is omitted, the wrapped function’s __name__ is used automatically.Explicit input value to record for this run. When provided to the context manager form, it is stored as the
user_input event. When used as a decorator, NorthStar captures the function’s arguments automatically and input is not needed.Arbitrary key-value pairs merged into the run’s metadata. Useful for routing, filtering, or annotating runs in the dashboard. Project name and environment (set in
init()) are always included automatically.A list of string tags stored under
metadata["tags"] on the run. Tags appear in the dashboard and can be used for filtering.Override the global
capture_inputs setting from init() for this trace only. Set to False to prevent function arguments from being recorded as user_input events.Override the global
capture_outputs setting from init() for this trace only. Set to False to prevent return values from being recorded as final_response events.Decorator form
Apply@northstar.trace(...) above a function definition. When the function is called, a new trace run is started, arguments are captured as input, the return value is captured as output, and the run is finished and flushed when the function returns. Exceptions are recorded as errors on the run and re-raised.
When
name is omitted from the decorator, the function’s __name__ is used
as the run name. For example, @northstar.trace() on a function called
run_agent produces a run named "run_agent".Context manager form
Usewith northstar.trace(...) as trace: when you need explicit control — for example, to call trace.set_output() with a value computed at the end of a block, or to attach structured logging mid-run.
_TraceHandle methods
Inside the with block, the context manager yields a _TraceHandle (or a silent no-op stub if the SDK is disabled). The handle exposes these methods:
Records
output as the final_response event for this run. Call this once at the end of the block to capture the agent’s answer. Respects the capture_output flag.Attaches a named custom event to the run. Equivalent to calling
northstar.log_event() at trace scope.Records a numeric metric on the run.
value must be a real number — bool is rejected.Merges
metadata into the run’s metadata dictionary.Opens a
SpanKind.MODEL span attached directly to this run and yields a ModelSpan handle. Use this as a context manager to record LLM input messages, output messages, and token usage when you already hold a _TraceHandle reference.Async support
@northstar.trace() works transparently on async def functions. The trace is started before the coroutine is awaited and finished after it resolves, preserving the correct span context across await boundaries.