NorthStar provides four lightweight logging functions —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.
log_event(), log_metric(), log_metadata(), and current_trace_id() — that let you attach structured data to the active trace or span from anywhere in your call stack. Unlike span() or observe(), they do not create new spans or alter the trace hierarchy; they simply annotate whatever is currently in scope. A fifth helper, flush(), lets you drain the queue synchronously when you need a hard guarantee that data has been sent before the process exits.
All five functions are top-level exports of the northstar package and are safe to call from any thread.
log_event()
EventType.CUSTOM records and are visible in the dashboard’s event timeline.
A short, dot-namespaced or snake_case label identifying the event, e.g.
"cache_miss", "fallback_triggered", or "retrieval_started".Any JSON-serialisable value associated with the event. Dicts, lists, primitives, Pydantic models, and dataclasses are all accepted. Sensitive keys matching the redact list are replaced with
"[REDACTED]" before the event is enqueued.log_event() is a no-op when called outside any active trace. It never
raises an exception, so it is safe to call unconditionally.log_metric()
EventType.CUSTOM records with attributes["northstar_type"] = "metric" and are displayed separately from events in the dashboard.
Metric name, e.g.
"retrieval_count", "confidence", "latency_ms".A numeric value (
int or float). bool is explicitly rejected — passing True or False raises TypeError: metric value must be numeric. This guard prevents accidental boolean-as-number mistakes.log_metadata()
metadata into the current span’s attributes dictionary, or into the run’s metadata dictionary if no span is active. The update is shallow (dict.update()), so existing keys that are not in metadata are preserved. The updated record is re-enqueued immediately so dashboard views reflect the change without waiting for the next flush.
Key-value pairs to merge. Values must be JSON-serialisable. Sensitive keys are redacted automatically.
current_trace_id()
str, or None if called outside any trace. Use this to correlate your application’s own log lines with NorthStar trace records.
Example — structured logging correlation:
current_trace_id() returns None before northstar.init() is called,
outside a trace() block, and in no-op mode. Check the return value before
passing it to external systems.flush()
True if the flush succeeded, False if an error occurred (network failure, timeout, etc.).
Maximum seconds to wait for the HTTP request to complete. When
None, the client’s default timeout applies. Must be greater than zero if provided; raises ValueError otherwise.