Skip to main content

Lightweight OpenTelemetry-native tracing for LLM and AI agent applications

Project description

agentrace-ai

Lightweight OpenTelemetry-native tracing for LLM and AI agent applications.

pip install agentrace-ai

Quick Start

import agentrace
from agentrace import trace_llm, trace_tool, trace_agent

agentrace.init(service_name="my-agent")

@trace_tool(tool_name="search")
def search(query):
    return ["result1", "result2"]

@trace_llm(model="gpt-4o")
def call_llm(messages):
    return client.chat.completions.create(model="gpt-4o", messages=messages)

@trace_agent(name="research-agent")
def run(question):
    results = search(question)
    return call_llm([{"role": "user", "content": str(results)}])

run("What is OpenTelemetry?")
agentrace.shutdown()

Features

  • Decorators: @observe, @trace_llm, @trace_tool, @trace_agent, @trace_chain, @trace_retrieval
  • Context Managers: trace_span(), trace_llm_call() with .record_response()
  • Session Tracking: set_session(), set_user(), session_context()
  • Cost Tracking: Auto-calculates cost from token usage for OpenAI and Anthropic models
  • Auto-Instrumentation: Monkey-patch OpenAI/Anthropic SDKs with one line
  • LangChain Callback: AgentraceCallbackHandler for LangChain/LangGraph
  • Export Anywhere: Console, OTLP (gRPC/HTTP), or build your own exporter
  • Lightweight: Only 2 dependencies (opentelemetry-api + opentelemetry-sdk)

Integrations

pip install agentrace-ai[openai]      # OpenAI auto-instrumentation
pip install agentrace-ai[anthropic]   # Anthropic auto-instrumentation
pip install agentrace-ai[langchain]   # LangChain callback handler
pip install agentrace-ai[otlp]       # OTLP exporter (Jaeger, Grafana, etc.)
pip install agentrace-ai[all]        # Everything

Auto-instrument OpenAI

from agentrace.integrations import openai_patch
openai_patch.instrument()
# All OpenAI calls are now traced automatically

Auto-instrument Anthropic

from agentrace.integrations import anthropic_patch
anthropic_patch.instrument()

LangChain / LangGraph

from agentrace.integrations.langchain_cb import AgentraceCallbackHandler
chain.invoke({"input": "..."}, config={"callbacks": [AgentraceCallbackHandler()]})

Export to OTLP (Jaeger, Grafana Tempo, etc.)

agentrace.init(
    service_name="my-agent",
    exporters=["console", "otlp"],
    otlp_endpoint="http://localhost:4317",
)

License

MIT

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

agentrace_ai-0.1.0.tar.gz (17.1 kB view details)

Uploaded Source

Built Distribution

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

agentrace_ai-0.1.0-py3-none-any.whl (20.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: agentrace_ai-0.1.0.tar.gz
  • Upload date:
  • Size: 17.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for agentrace_ai-0.1.0.tar.gz
Algorithm Hash digest
SHA256 916009559a07b2e3236939ff6afc9b30c4d1c6735b90d35a827590275becef26
MD5 590a89b4abe7907ef035df689ad702c1
BLAKE2b-256 efb43086e51aeebf2689c3f783e9527dc7c22698c342adcfa4b7ab42dd878b71

See more details on using hashes here.

File details

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

File metadata

  • Download URL: agentrace_ai-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 20.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for agentrace_ai-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 27589d92a08dc09174f6eab7fcc36f601bde203be1775c49b7d7d4808dd338fd
MD5 48ee1276e037c2ca81f0f3da16c45907
BLAKE2b-256 55393911b7b63863a45a47573a3e3eb158bed5bb724f9ce6c67be96a5b714712

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