Auto-Instrumentation

SDK

Automatically trace LLM calls and popular libraries.

Traccia automatically instruments popular LLM providers and frameworks. When you install Traccia with the appropriate extras, tracing is enabled without any code changes.

Supported Libraries

🤖LLM Providers

OpenAI
≥1.0.0 (Py) / ≥4.0.0 (Node)
Anthropic
≥0.18.0 (Py) / ≥0.20.0 (Node)

Frameworks

FastAPI / Express
latest
Requests / Axios
latest

What Gets Traced

OpenAI

All chat.completions.create() and completions.create() calls are traced with:

  • Model name
  • Token counts
  • Estimated cost
  • Latency
  • Streaming support
  • Tool/function calls

Anthropic

All messages.create() calls are traced with:

  • Model name
  • Token counts
  • Estimated cost
  • Latency
  • Stop reason

Data capture

Traccia captures prompts and completions (truncated to 1000 chars) for debugging purposes. This data is sent to your configured backend. If handling sensitive data, export to your own local backend (Jaeger/Tempo) or disable specific attributes via custom processors.

Example

With auto-instrumentation, you don't need to modify your existing code:

agent.py
python
from traccia import init
from openai import OpenAI
# Initialize Traccia
init()
# Your existing code - no changes needed!
client = OpenAI()
# This call is automatically traced
response = client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": "Hello!"}]
)
# Trace will include:
# - Model: gpt-4
# - Prompt tokens: ~10
# - Completion tokens: ~50
# - Cost: ~$0.002
# - Latency: ~800ms

Disabling Auto-Instrumentation

You can disable all auto-instrumentations programmatically:

main.py
python
from traccia import init
# Disable all auto-patching
init(enable_patching=False)

Or via configuration file:

traccia.toml
toml
[instrumentation]
enable_patching = false

Or via environment variable:

bash
export TRACCIA_ENABLE_PATCHING=false
# Or legacy variable
export AGENT_DASHBOARD_ENABLE_PATCHING=false

Selective disabling

Currently, auto-instrumentation is all-or-nothing. If you need to selectively disable specific libraries, set enable_patching=False and use the @observe() decorator manually where needed.

Additional Auto-Instrumentation Features

Token Counting

Traccia automatically counts tokens for LLM calls using the tiktoken library. This works for all OpenAI models and provides estimates for others.

Disable with enable_token_counting=False

Cost Calculation

Traccia automatically calculates estimated costs based on token usage and model pricing. You can customize pricing tables via environment variables.

Disable with enable_costs=False

Context Propagation

When auto-instrumentation is enabled for requests and FastAPI, trace context is automatically propagated across HTTP boundaries using W3C Trace Context headers.

python
# No manual propagation needed!
import requests
# Trace context automatically injected
response = requests.get("http://other-service/api")

Next Steps

© 2026 Traccia.