Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nightgaze-0.2.0.tar.gz (32.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nightgaze-0.2.0-py3-none-any.whl (35.4 kB view details)

Uploaded Python 3

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

Hashes for nightgaze-0.2.0.tar.gz
Algorithm Hash digest
SHA256 bec2f4bde3ae97406cc6f54837d6daf084f135e4e64f791f39b90efe6adbee9f
MD5 7299c4a78022c9288630d2d78f366ce9
BLAKE2b-256 78cd1a82fe646b7db58f8eb3bc1c90a4991b57666feea927be1e451295fa6ec5

See more details on using hashes here.

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

Hashes for nightgaze-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2b09ae10cba0222156c836d3db2bd2b7c41367540c98e5c2e4473c44e1971091
MD5 6c6af78b4eb821f2fbbefe5c1997911a
BLAKE2b-256 aaffa6895d62e0db63aaafb67c51369ea43c00cea5abf7bd7ddf47da8a5ad6e7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page