Skip to main content

Distributed tracing and observability for AI agents. Datadog for AI Agents.

Project description

๐Ÿ” traceweave

Distributed Tracing & Observability for AI Agents

See exactly what your AI agents are doing. Debug multi-agent systems like a pro.

PyPI version Python 3.9+ License: MIT Downloads

English | ็ฎ€ไฝ“ไธญๆ–‡ | ๆ—ฅๆœฌ่ชž | ํ•œ๊ตญ์–ด | Espaรฑol

Quick Start ยท Features ยท Integrations ยท Dashboard ยท Examples


Think of it as Datadog for AI Agents. Trace every agent decision, tool call, and LLM interaction with beautiful visualizations and zero-config instrumentation.

๐Ÿ“ Trace: multi-agent-research  id=a3f2c1d8...
โ”œโ”€โ”€ โœ… ๐Ÿ”— multi-agent-research           โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‘โ–‘ 12.3s   tokens: 8.2k   cost: $0.15
โ”‚   โ”œโ”€โ”€ โœ… ๐Ÿค– planner                    โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘  3.2s    tokens: 2.1k   cost: $0.04
โ”‚   โ”‚   โ””โ”€โ”€ โœ… ๐Ÿง  plan-generation        โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘  2.1s    tokens: 1.8k   cost: $0.03
โ”‚   โ”œโ”€โ”€ โœ… ๐Ÿค– researcher                 โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘  5.1s    tokens: 3.4k   cost: $0.06
โ”‚   โ”‚   โ”œโ”€โ”€ โœ… ๐Ÿ”ง web-search             โ–ˆโ–ˆโ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘  0.6s    tokens: -      cost: -
โ”‚   โ”‚   โ”œโ”€โ”€ โœ… ๐Ÿ”ง arxiv-search           โ–ˆโ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘  0.3s    tokens: -      cost: -
โ”‚   โ”‚   โ””โ”€โ”€ โœ… ๐Ÿง  analyze-results        โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘  3.1s    tokens: 2.8k   cost: $0.05
โ”‚   โ”œโ”€โ”€ โœ… ๐Ÿค– writer                     โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘  4.8s    tokens: 1.9k   cost: $0.04
โ”‚   โ”‚   โ””โ”€โ”€ โœ… ๐Ÿง  write-report           โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘  4.2s    tokens: 1.9k   cost: $0.04
โ”‚   โ””โ”€โ”€ โœ… ๐Ÿค– reviewer                   โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘  2.4s    tokens: 0.8k   cost: $0.01
โ”‚       โ””โ”€โ”€ โœ… ๐Ÿง  review-report          โ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–ˆโ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘โ–‘  2.1s    tokens: 0.8k   cost: $0.01
โ•ฐโ”€โ”€ Summary โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
    โฑ  Duration: 12.3s โ”‚ ๐Ÿ”ข Spans: 11 โ”‚ ๐Ÿ“Š Tokens: 8.2k โ”‚ ๐Ÿ’ฐ Cost: $0.15

Why traceweave?

Building with AI agents? You've probably experienced:

  • ๐Ÿคฏ "Why did my agent do that?" โ€” No visibility into agent reasoning chains
  • ๐Ÿ’ธ "Where are my tokens going?" โ€” Can't track costs across nested agent calls
  • ๐Ÿ› "Which step failed?" โ€” Debugging multi-agent pipelines is a nightmare
  • ๐Ÿ“Š "How long does each step take?" โ€” No performance profiling for agents

traceweave solves all of this with 2 lines of code.

๐Ÿš€ Quick Start

pip install traceweave
from agent_trace import tracer, trace_agent, trace_tool
from agent_trace.dashboard.tui import print_trace

@trace_tool("calculator")
def add(a: int, b: int) -> int:
    return a + b

@trace_agent("math-agent")
def math_agent(question: str) -> int:
    return add(2, 3)

# Trace everything
with tracer.start_trace("math-task"):
    answer = math_agent("What is 2 + 3?")

# Visualize
print_trace(tracer.get_all_traces()[-1])

โœจ Features

๐ŸŽฏ Zero-Config Auto-Instrumentation

Automatically trace OpenAI, Anthropic, and LangChain with a single line:

from agent_trace.integrations import instrument_all
instrument_all()  # That's it! All LLM calls are now traced.

๐Ÿค– Elegant Decorators

@trace_agent("researcher")    # Trace agent functions
@trace_tool("web-search")     # Trace tool calls
@trace_llm(model="gpt-4")     # Trace LLM calls with token tracking

๐Ÿ“Š Token & Cost Tracking

Automatic token counting and cost estimation for all major models:

with tracer.start_span("my-llm-call", SpanKind.LLM) as span:
    response = call_llm(prompt)
    span.set_token_usage(
        prompt_tokens=1500,
        completion_tokens=500,
        model="claude-3-sonnet",
        prompt_cost_per_1k=0.003,
        completion_cost_per_1k=0.015,
    )

๐Ÿ–ฅ๏ธ Beautiful Terminal Dashboard

traceweave tui  # Live-updating terminal dashboard

๐ŸŒ Web Dashboard

traceweave dashboard  # Opens at http://localhost:8420

Dark-themed, real-time web dashboard with:

  • Interactive trace tree visualization
  • Token usage analytics
  • Cost breakdown per agent/tool
  • Timeline waterfall view

๐Ÿ“ค Export Anywhere

from agent_trace.exporters import export_json, export_chrome

# Save as JSON
export_json(trace, "my-trace.json")

# Export to Chrome DevTools format (open in chrome://tracing)
export_chrome(trace, "my-trace.chrome.json")

๐Ÿ”Œ Integrations

OpenAI

from agent_trace.integrations.openai_integration import instrument_openai
instrument_openai()

# All OpenAI calls are now traced automatically!
client = openai.OpenAI()
response = client.chat.completions.create(
    model="gpt-4",
    messages=[{"role": "user", "content": "Hello!"}]
)

Anthropic

from agent_trace.integrations.anthropic_integration import instrument_anthropic
instrument_anthropic()

# All Anthropic calls are now traced!
client = anthropic.Anthropic()
response = client.messages.create(
    model="claude-3-sonnet-20240229",
    messages=[{"role": "user", "content": "Hello!"}]
)

LangChain

from agent_trace.integrations.langchain_integration import AgentTraceCallbackHandler

handler = AgentTraceCallbackHandler()
chain = prompt | llm | output_parser
chain.invoke({"input": "..."}, config={"callbacks": [handler]})

๐Ÿ“ Examples

Example Description
Simple Demo Minimal example โ€” trace in 10 lines
Multi-Agent Research 4-agent team with tools, LLM calls, and cost tracking

Run the built-in demo:

traceweave demo

๐Ÿ—๏ธ Architecture

traceweave/
โ”œโ”€โ”€ agent_trace/
โ”‚   โ”œโ”€โ”€ core/           # Core tracing engine
โ”‚   โ”‚   โ”œโ”€โ”€ models.py   # Pydantic data models (Span, Trace, TokenUsage)
โ”‚   โ”‚   โ”œโ”€โ”€ tracer.py   # Main tracer with context management
โ”‚   โ”‚   โ”œโ”€โ”€ span.py     # Span context manager
โ”‚   โ”‚   โ”œโ”€โ”€ context.py  # Thread-safe context propagation
โ”‚   โ”‚   โ””โ”€โ”€ decorators.py # @trace_agent, @trace_tool, @trace_llm
โ”‚   โ”œโ”€โ”€ integrations/   # Framework auto-instrumentation
โ”‚   โ”‚   โ”œโ”€โ”€ openai_integration.py
โ”‚   โ”‚   โ”œโ”€โ”€ anthropic_integration.py
โ”‚   โ”‚   โ””โ”€โ”€ langchain_integration.py
โ”‚   โ”œโ”€โ”€ dashboard/      # Visualization
โ”‚   โ”‚   โ”œโ”€โ”€ tui.py      # Rich terminal dashboard
โ”‚   โ”‚   โ””โ”€โ”€ server.py   # Web dashboard (single HTML, no build step)
โ”‚   โ”œโ”€โ”€ exporters/      # Export formats
โ”‚   โ”‚   โ”œโ”€โ”€ json_exporter.py
โ”‚   โ”‚   โ””โ”€โ”€ chrome_exporter.py
โ”‚   โ””โ”€โ”€ cli.py          # CLI commands
โ””โ”€โ”€ examples/           # Demo scripts

๐Ÿ”‘ Key Concepts

Concept Description
Trace A complete operation (e.g., "research task"). Contains a tree of spans.
Span A single unit of work (agent call, tool use, LLM request).
SpanKind Type of span: AGENT, TOOL, LLM, CHAIN, RETRIEVER
TokenUsage Token counts + cost estimation per LLM call

๐Ÿ“ฆ Installation

# Core only
pip install traceweave

# With specific integrations
pip install traceweave[openai]
pip install traceweave[anthropic]
pip install traceweave[langchain]

# Everything
pip install traceweave[all]

Requirements: Python 3.9+

๐Ÿค Contributing

Contributions welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing)
  5. Open a Pull Request

๐Ÿ“„ License

MIT License โ€” see LICENSE for details.


Built with โค๏ธ for the AI agent community

If you find traceweave useful, please โญ star the repo!

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

traceweave-0.1.2.tar.gz (40.2 kB view details)

Uploaded Source

Built Distribution

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

traceweave-0.1.2-py3-none-any.whl (34.5 kB view details)

Uploaded Python 3

File details

Details for the file traceweave-0.1.2.tar.gz.

File metadata

  • Download URL: traceweave-0.1.2.tar.gz
  • Upload date:
  • Size: 40.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for traceweave-0.1.2.tar.gz
Algorithm Hash digest
SHA256 6445ca6dd564d4a8562e511902487fec7152fd342887d1891b5ae48488c4ed3b
MD5 85bd81a7981ff925a140bc6eadaf4a2e
BLAKE2b-256 8297cb6b729543613683f5e44aeb487a6f7837f81d7ec6631e0d57bd80ba45aa

See more details on using hashes here.

File details

Details for the file traceweave-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: traceweave-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 34.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for traceweave-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b5992b3fd160e163343ab4da955afaf80130309129085c77206be33b93e439ae
MD5 7984675891a705afc6d2af5526e9f92b
BLAKE2b-256 40187e289054864b9938e16b275a5bf3a1cd7f1c9a5fff64ddc29f5ba4aa8d85

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