Skip to main content

OpenTelemetry-based observability for autonomous AI agent systems

Project description

AgentTelemetry

PyPI version Python versions License

OpenTelemetry-based observability for AI agent systems. Provides 9 agent-specific span kinds, 7 framework adapters, privacy controls, and analysis tools for fault detection in autonomous agents.

Installation

pip install agenttelemetry

Quickstart

from agenttelemetry import configure, start_agent_span, AgentSpanKind

# One-line setup: configure tracing with console output
provider = configure(service_name="my-agent", console=True)
tracer = provider.get_tracer()

# Trace an agent task
with start_agent_span("research-task", AgentSpanKind.AGENT, tracer=tracer) as span:
    span.set_attribute("agent.name", "researcher")

    with start_agent_span("call-gpt4", AgentSpanKind.LLM_CALL, tracer=tracer) as llm:
        llm.set_attribute("llm.model", "gpt-4o")
        llm.set_attribute("llm.input_tokens", 500)
        llm.set_attribute("llm.output_tokens", 200)

    with start_agent_span("web-search", AgentSpanKind.TOOL_CALL, tracer=tracer) as tool:
        tool.set_attribute("tool.name", "search")
        tool.set_attribute("tool.status", "success")

Features

  • 9 agent-specific span kinds -- AGENT, LLM_CALL, TOOL_CALL, PLANNING, REASONING, RETRIEVAL, GUARD_RAIL, DELEGATION, MEMORY
  • 7 framework adapters -- auto-instrumentation for LangChain, CrewAI, AutoGen, Anthropic SDK, OpenAI SDK, LlamaIndex, and a manual API for custom agents
  • 3 privacy levels -- NONE (structural only), METADATA_ONLY (default; adds model names, token counts, costs), FULL (captures prompt/completion content)
  • 4 analysis modules -- anomaly detection, cost aggregation, decision attribution, hallucination tracing
  • Built on OpenTelemetry -- exports to Jaeger, Grafana Tempo, Datadog, or any OTLP-compatible backend
  • Cost estimation -- automatic USD cost calculation for OpenAI and Anthropic models

Framework Adapters

Framework Adapter Class Strategy LOC
LangChain LangChainInstrumentor Callback handler 359
CrewAI CrewAIInstrumentor Hook system 264
AutoGen AutoGenInstrumentor Monkey-patch 256
Anthropic SDK AnthropicInstrumentor Monkey-patch 294
OpenAI SDK OpenAIInstrumentor Monkey-patch 245
LlamaIndex LlamaIndexInstrumentor Span handler 280
Custom start_agent_span etc. Context managers 315

Each adapter uses lazy imports -- the framework package is only required at instrument() time, not at import time.

Auto-instrumentation Example (OpenAI)

from agenttelemetry import configure
from agenttelemetry.adapters import OpenAIInstrumentor

provider = configure(service_name="my-agent", console=True)
instrumentor = OpenAIInstrumentor()
instrumentor.instrument(tracer_provider=provider.tracer_provider)

# All openai.chat.completions.create() calls are now traced automatically

Analysis Modules

Module Class Description
Anomaly Detection AnomalyDetector Detects circular delegation, infinite retries, cost explosions, and context overflow
Cost Aggregation CostAggregator Aggregates token counts and USD costs by model, agent, and trace
Decision Attribution DecisionAttributor Links each tool call back to the LLM decision that triggered it
Hallucination Tracing HallucinationTracer Identifies LLM outputs not grounded in retrieved content (token-overlap heuristic)

Benchmark Results

In fault-detection experiments, AgentTelemetry detects 8 out of 8 fault types at FDR = 1.0:

  • Circular delegation loops
  • Infinite tool retry loops
  • Cost explosion (runaway spending)
  • Context window overflow
  • Ungrounded LLM outputs (hallucination candidates)
  • Unattributed tool decisions
  • Token budget violations
  • Latency anomalies

Privacy Controls

from agenttelemetry import configure, PrivacyLevel

# Default: captures metadata but not prompt/completion content
provider = configure(service_name="my-agent", privacy_level=PrivacyLevel.METADATA_ONLY)

# Full capture for debugging (opt-in)
provider = configure(service_name="my-agent", privacy_level=PrivacyLevel.FULL)

# Minimal: structural info only (span kinds, timing, status)
provider = configure(service_name="my-agent", privacy_level=PrivacyLevel.NONE)

API Reference

Core

  • configure(service_name, privacy_level, console, json_file) -- one-line setup, returns AgentTelemetryProvider
  • AgentTelemetryProvider -- wraps OTel TracerProvider with agent-specific defaults
  • start_agent_span(name, kind, tracer, attributes) -- context manager for agent spans
  • AgentSpanKind -- enum of 9 span kinds
  • PrivacyLevel -- NONE, METADATA_ONLY, FULL

Adapters

  • AnthropicInstrumentor, OpenAIInstrumentor, LangChainInstrumentor, CrewAIInstrumentor, AutoGenInstrumentor, LlamaIndexInstrumentor
  • Manual helpers: start_llm_span, start_tool_span, start_retrieval_span, start_planning_span, start_reasoning_span, start_guardrail_span, start_delegation_span, start_memory_span

Analysis

  • AnomalyDetector / Anomaly / AnomalyType
  • CostAggregator / CostReport / ModelCost
  • DecisionAttributor / ToolDecision
  • HallucinationTracer / HallucinationCandidate

Contributing

See CONTRIBUTING.md for development setup, code structure, and guidelines.

License

This project is licensed under the Apache License 2.0. See LICENSE for the full text.

Citation

If you use AgentTelemetry in your research, please cite:

@software{agenttelemetry2025,
  title     = {AgentTelemetry: OpenTelemetry-Based Observability for AI Agent Systems},
  author    = {Balusu, Krishna Chaitanya},
  year      = {2025},
  url       = {https://github.com/agenttelemetry/agenttelemetry},
  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

agenttelemetry-0.1.0.tar.gz (1.4 MB view details)

Uploaded Source

Built Distribution

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

agenttelemetry-0.1.0-py3-none-any.whl (45.1 kB view details)

Uploaded Python 3

File details

Details for the file agenttelemetry-0.1.0.tar.gz.

File metadata

  • Download URL: agenttelemetry-0.1.0.tar.gz
  • Upload date:
  • Size: 1.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13+meta

File hashes

Hashes for agenttelemetry-0.1.0.tar.gz
Algorithm Hash digest
SHA256 cb5bd7093f4df1729629e91faba1639a6a84bb8eecf371857c6bf6df0d8e06c3
MD5 eaed7cfd917a186e27b6d3c462172cc3
BLAKE2b-256 b1145aa3abdf0953e90494ffa99dee9c9c53c16b69365940c3bbf660fa10bc40

See more details on using hashes here.

File details

Details for the file agenttelemetry-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: agenttelemetry-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 45.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13+meta

File hashes

Hashes for agenttelemetry-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 40a41d2c44a9088261c4c254f2358a992ffc04228eb23f71bae45aa3478c76b8
MD5 08ad47e58abde2479ab3f7742dc4fc46
BLAKE2b-256 ef75d9f825ca8a2542672d7856bc42ac3ec7254043b16c4c5a508006853c85d8

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