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.observe() is a decorator factory that wraps a function in a child span tied to the currently active trace. Every time the decorated function is called, NorthStar opens a span for it, captures the function’s arguments as tool_arguments events and the return value as a tool_result event, then closes the span when the function returns. This is the primary way to add structured observability to helper functions, tool calls, retrieval steps, and any other sub-operations inside an agent run.
observe vs trace
northstar.trace() | northstar.observe() | |
|---|---|---|
| Creates | A new top-level Run | A child Span inside an existing Run |
| Usage | Entry point of your agent | Sub-functions called within the agent |
| Without active trace | Starts a fresh run | No-op — silently does nothing |
| Form | Decorator or context manager | Decorator only |
Function signature
Parameters
Display name for the child span. Shown in the trace waterfall on the dashboard. When omitted, the wrapped function’s
__name__ is used automatically.Arbitrary key-value metadata attached to the span’s
attributes dictionary. Use this to add static context that doesn’t change between calls (e.g. {"index": "docs-v2"}). For dynamic per-call data, prefer log_event() or log_metadata() inside the function body.Basic decorator example
retrieve_docs("How does caching work?") is called inside an active trace:
- A child span named
"retrieve-docs"is opened. {"query": "How does caching work?"}is recorded as atool_argumentsevent.- The function body executes;
log_eventattaches a custom event to the span. - The return value is recorded as a
tool_resultevent. - The span is closed with latency and status.
Composing with @northstar.trace
retrieve-docs and generate-answer) visible in the trace waterfall.
Span nesting
@northstar.observe spans nest automatically. If an observed function calls another observed function, the inner span becomes a child of the outer span — no configuration required. The parent-child relationship is tracked via Python’s ContextVar.
Attaching static attributes
Async support
@northstar.observe() works transparently with async def functions. The span is started before the coroutine is awaited and closed after it resolves, correctly propagating the span context across await points.
observe() vs span()
@northstar.observe() | northstar.span() | |
|---|---|---|
| Form | Decorator | Context manager (with) |
| Input capture | Auto — from function arguments | Manual — call log_event() yourself |
| Output capture | Auto — from return value | Manual |
| Best for | Existing functions, tool wrappers | Inline code blocks |
If
@northstar.observe() is called on a function that runs outside an
active trace, it is a complete no-op. The function executes normally and no
span is created. This means you can safely decorate shared utilities without
worrying about calls that happen at import time or in tests.