Auto-Instrumentation
SDKAutomatically 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
≥1.0.0 (Py) / ≥4.0.0 (Node)≥0.18.0 (Py) / ≥0.20.0 (Node)⚡Frameworks
latestlatestWhat 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
Example
With auto-instrumentation, you don't need to modify your existing code:
from traccia import initfrom openai import OpenAI
# Initialize Tracciainit()
# Your existing code - no changes needed!client = OpenAI()
# This call is automatically tracedresponse = 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: ~800msDisabling Auto-Instrumentation
You can disable all auto-instrumentations programmatically:
from traccia import init
# Disable all auto-patchinginit(enable_patching=False)Or via configuration file:
[instrumentation]enable_patching = falseOr via environment variable:
export TRACCIA_ENABLE_PATCHING=false# Or legacy variableexport AGENT_DASHBOARD_ENABLE_PATCHING=falseSelective disabling
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.
# No manual propagation needed!import requests
# Trace context automatically injectedresponse = requests.get("http://other-service/api")Next Steps
© 2026 Traccia.