Observability for AI agents — trace agents, tools, MCP and LLM calls with token usage, cost and latency
Project description
NightGaze
Observability for AI agents. Trace your agents, tools, MCP and LLM calls with two lines of code — and see every step, token, and millisecond of your agent workflows.
Installation
pip install nightgaze
Quick start
import nightgaze
nightgaze.init(
api_key="ng_live_...", # from your NightGaze project settings
base_url="https://your-nightgaze-host.com",
)
@nightgaze.agent("planner")
def plan_trip(query: str) -> str:
hotels = search_hotels(query)
return summarize(hotels)
@nightgaze.tool("search_hotels")
def search_hotels(query: str) -> list:
...
That's it. The outermost call becomes a trace; everything inside it — nested functions, LLM calls, tool calls — becomes a child span with timing, token usage, and error capture. Works with sync, async, and generator functions.
Trace your LLM calls automatically
nightgaze.instrument_openai() # Chat Completions + Responses API
nightgaze.instrument_anthropic() # Messages API
nightgaze.instrument_gemini() # Google Gemini (google-genai)
Every request is captured with model, token usage, latency, and time-to-first-token for streaming — no changes to your calling code.
Framework integrations
nightgaze.instrument_langchain() # chains, LLMs, tools, retrievers
nightgaze.instrument_langgraph() # graphs with named node spans
nightgaze.instrument_llamaindex() # queries, retrieval, synthesis
Decorators and manual spans
@nightgaze.agent("researcher") # agent step
@nightgaze.tool("web_search") # tool call
@nightgaze.trace("checkout") # explicit workflow root
@nightgaze.mcp("fetch_docs") # MCP tool call
@nightgaze.span # generic span
# or as a context manager, with custom attributes:
with nightgaze.span_context("rerank", kind="tool") as span:
results = rerank(docs)
span.add_metadata(doc_count=len(results))
Attribute traces to your users
nightgaze.identify(user_id="u_123", session_id="sess_9", customer_id="acme")
Every event emitted afterwards carries these identifiers, so you can filter traces by user, follow a session end-to-end, and break down cost per customer.
Streaming support
Streamed LLM responses are traced correctly: the span stays open until the
stream is consumed (full generation latency) and records
time_to_first_token_ms.
Safe by design
- Never breaks your app — after
init(), telemetry is best-effort; any failure means a dropped event, never an exception in your code. - Off the hot path — events batch in the background with compression, retries, and a circuit breaker. Fork-safe under gunicorn/celery.
Optional extras
pip install "nightgaze[openai]" # openai
pip install "nightgaze[anthropic]" # anthropic
pip install "nightgaze[gemini]" # google-genai
pip install "nightgaze[langchain]" # langchain-core
pip install "nightgaze[langgraph]" # langgraph
pip install "nightgaze[llamaindex]" # llama-index-core
Requirements
Python 3.9+
License
Apache-2.0
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nightgaze-0.2.0.tar.gz.
File metadata
- Download URL: nightgaze-0.2.0.tar.gz
- Upload date:
- Size: 32.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bec2f4bde3ae97406cc6f54837d6daf084f135e4e64f791f39b90efe6adbee9f
|
|
| MD5 |
7299c4a78022c9288630d2d78f366ce9
|
|
| BLAKE2b-256 |
78cd1a82fe646b7db58f8eb3bc1c90a4991b57666feea927be1e451295fa6ec5
|
File details
Details for the file nightgaze-0.2.0-py3-none-any.whl.
File metadata
- Download URL: nightgaze-0.2.0-py3-none-any.whl
- Upload date:
- Size: 35.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2b09ae10cba0222156c836d3db2bd2b7c41367540c98e5c2e4473c44e1971091
|
|
| MD5 |
6c6af78b4eb821f2fbbefe5c1997911a
|
|
| BLAKE2b-256 |
aaffa6895d62e0db63aaafb67c51369ea43c00cea5abf7bd7ddf47da8a5ad6e7
|