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.span() is a context manager that opens a child span inside the currently active trace, runs the code block inside the with statement, then closes the span when the block exits — recording latency, status, and any errors automatically. Use span() when you want to trace an inline code block rather than wrapping an existing function with @northstar.observe(). Spans can be freely nested; parent-child relationships are resolved automatically via Python ContextVars so you never need to pass handles manually.
Function signature
Parameters
Display name for the span shown in the trace waterfall on the dashboard. Required.
Category of work this span represents. Used by the dashboard for grouping, filtering, and cost roll-ups. See the
SpanKind table below.Optional integer label for loop iterations, retry attempts, or parallel branches. Shown alongside the span name in the dashboard to disambiguate repeated steps. For example, pass
iteration=attempt_number when retrying a flaky tool call.Arbitrary key-value metadata stored in the span’s
attributes dictionary. Values must be JSON-serialisable. Sensitive keys matching the redact list (e.g. api_key, token) are replaced with "[REDACTED]" automatically.SpanKind values
SpanKind is a StrEnum defined in northstar.models. Import it from the top-level northstar package.
| Value | String | Meaning |
|---|---|---|
SpanKind.AGENT | "agent" | A nested agent or sub-agent invocation |
SpanKind.WORKFLOW | "workflow" | A multi-step orchestration or pipeline stage |
SpanKind.MODEL | "model" | An LLM or model call (used internally by model_call()) |
SpanKind.TOOL | "tool" | An external tool call, API call, or function execution |
SpanKind.CUSTOM | "custom" | Any other instrumented step (default) |
Basic usage
_SpanHandle methods
Inside the with block the handle exposes:
Attaches a named custom event to this span.
data can be any JSON-serialisable value.The UUID of the underlying
Span record. Useful when you need to cross-reference a span with an external system.Nested spans
Spans nest automatically. Whennorthstar.span() is called inside another with northstar.span(...) block, the inner span’s parent_span_id is set to the outer span’s id with no extra code.
Iteration parameter
Passiteration when repeating a span in a loop, so each attempt is distinguishable in the dashboard.
Attaching span attributes
No-op behavior
northstar.span() returns a _NoopSpan when:
- There is no active trace (i.e.,
northstar.trace()was not called before this point), or - The SDK is in disabled/unconfigured mode.
_NoopSpan is a valid context manager and its log_event() method silently discards data, so code inside the block continues to run normally.
For wrapping existing functions rather than inline blocks, prefer
@northstar.observe() — it captures function arguments and return values
automatically without manual log_event() calls.