Skip to main content
Use manual tracing when you need explicit control over what gets logged and when.

How it works

  • Create one NexusClient per request or workflow.
  • Create nested spans with client.span(...).
  • Set outputs or errors on spans.
  • Call client.flush() to persist buffered events.

Minimal example

Span behavior

  • A span gets a generated run_id.
  • The active parent span becomes parent_run_id for children.
  • Exceptions inside with client.span(...) mark the span as errored.
  • Exceptions are re-raised after logging because span context managers do not suppress them.

Choosing event_type

Use categories that map to your architecture:
  • chain
  • llm
  • chat_model
  • tool
  • agent
  • retriever
  • text
  • retry

Common pitfalls

NexusClient(api_key=...) converts strings into uuid.UUID. If your API key is not UUID-formatted, initialization fails.
  • Forgetting to call flush() means events stay in memory.
  • Passing non-JSON-serializable objects is allowed, but they are converted to strings.