Auto-Instrumentation
Calling trail.init() patches every supported library already installed in your environment. You
write no tracing code; their calls start emitting spans.
How it works
At init() time the SDK:
- Checks whether each supported library is importable.
- Skips it silently if not (logged at info level).
- Wraps its methods if present, so every call opens a span capturing model, prompt, completion, tokens, latency, and computed cost.
- Logs an error and continues if instrumenting one library fails — one bad instrumentor never takes down your process.
import trail
trail.init(application_name="my-app", url=..., public_key=..., secret_key=...)
from openai import OpenAI # ← constructed AFTER init
client = OpenAI()
client.chat.completions.create(...) # traced automatically
Order matters. A client constructed before trail.init() holds unpatched methods and won't be
traced.
Supported libraries
LLM providers
| Library | Instrumentor name | Module detected |
|---|---|---|
| OpenAI | openai |
openai |
| Anthropic | anthropic |
anthropic |
| Cohere | cohere |
cohere |
| Mistral | mistral |
mistralai |
| AWS Bedrock | bedrock |
boto3 |
| Google Vertex AI | vertexai |
vertexai |
| Google AI Studio | google-ai-studio |
google.genai |
| Azure AI Inference | azure-ai-inference |
azure.ai.inference |
| Groq | groq |
groq |
| Ollama | ollama |
ollama |
| GPT4All | gpt4all |
gpt4all |
| vLLM | vllm |
vllm |
| Together AI | together |
together |
| Reka | reka-api |
reka |
| PremAI | premai |
premai |
| AI21 | ai21 |
ai21 |
| LiteLLM | litellm |
litellm |
| Hugging Face Transformers | transformers |
transformers |
| ElevenLabs | elevenlabs |
elevenlabs |
| AssemblyAI | assemblyai |
assemblyai |
Agent & orchestration frameworks
| Library | Instrumentor name | Module detected |
|---|---|---|
| LangChain | langchain |
langchain |
| LlamaIndex | llama_index |
llama_index |
| Haystack | haystack |
haystack |
| CrewAI | crewai |
crewai |
| AG2 | ag2 |
ag2 |
| AutoGen | autogen |
autogen |
| PyAutoGen | pyautogen |
pyautogen |
| OpenAI Agents | openai-agents |
agents |
| Letta | letta |
letta |
| Phidata | phidata |
phi |
| Dynamiq | dynamiq |
dynamiq |
| ControlFlow | controlflow |
controlflow |
| Julep | julep |
julep |
| MultiOn | multion |
multion |
| EmbedChain | embedchain |
embedchain |
| Mem0 | mem0 |
mem0 |
Vector databases
| Library | Instrumentor name | Module detected |
|---|---|---|
| Chroma | chroma |
chromadb |
| Pinecone | pinecone |
pinecone |
| Qdrant | qdrant |
qdrant_client |
| Milvus | milvus |
pymilvus |
| AstraDB | astra |
astrapy |
Web scraping / data
| Library | Instrumentor name | Module detected |
|---|---|---|
| Crawl4AI | crawl4ai |
crawl4ai |
| FireCrawl | firecrawl |
firecrawl |
Hardware
| Target | Enabled by |
|---|
What gets captured
LLM calls
| Attribute | Example |
|---|---|
| Model | gpt-4o-mini |
| Provider / system | openai |
| Operation | chat, embedding, image, audio |
| Prompt | Full messages, by role (unless content capture is off) |
| Completion | The response (same caveat) |
| Prompt tokens | 1,247 |
| Completion tokens | 312 |
| Total tokens | 1,559 |
| Cost | Computed from the pricing table |
| Duration | End-to-end latency |
| TTFT | Time to first token (streaming) |
| TBT | Average time between tokens (streaming) |
| Parameters | Temperature, max tokens, top-p, … |
| Server address / port | Endpoint called |
| Status | Success or error, with exception detail |
Vector database operations
Operation type, collection/index name, query and result counts, duration, and system identity — which appear in the trace tree alongside the LLM calls they feed.
Agent frameworks
Agent names, task and tool executions, and step sequencing, emitted as OTel gen_ai.* attributes so
they populate Agent Analytics.
Disabling instrumentors
trail.init(
...,
disabled_instrumentors=["chroma", "pinecone"],
)
Instrumentor names
Use these exact strings — anything else is logged as a warning and ignored:
openai, anthropic, cohere, mistral, bedrock, vertexai, groq, ollama, gpt4all,
elevenlabs, vllm, google-ai-studio, azure-ai-inference, langchain, llama_index,
haystack, embedchain, mem0, chroma, pinecone, qdrant, milvus, transformers,
litellm, crewai, ag2, autogen, pyautogen, multion, dynamiq, phidata, reka-api,
premai, julep, astra, ai21, controlflow, assemblyai, crawl4ai, firecrawl,
letta, together, openai-agents
Note the inconsistencies: llama_index uses an underscore, google-ai-studio and reka-api use
hyphens, phidata maps to the phi module. Copy from this list rather than guessing.
Verifying a library is instrumented
- Run one call through the library.
- Open Observations → Tracing.
- Look for a span named after the operation.
Not seeing spans? Work down this list:
| Check | How |
|---|---|
| Is the library installed in the same environment? | pip show <library> |
Was trail.init() called before the client was constructed? |
Read the import and construction order |
Is the instrumentor in disabled_instrumentors? |
Check your init call |
| Did instrumentation error? | Enable debug logging (below) |
| Is the library supported at all? | The tables above |
Debug logging
import logging
logging.basicConfig(level=logging.DEBUG)
import trail
trail.init(...)
You'll see one line per instrumentor: instrumented, skipped (library absent), or failed.
Unsupported libraries
Instrument them yourself with @trail.trace:
@trail.trace(role="llm")
def call_custom_model(prompt: str) -> str:
return my_custom_client.generate(prompt)
You'll get the span, its timing, and its result. Token counts and cost need setting manually:
with trail.start_trace("custom_model_call", role="llm") as span:
result = my_custom_client.generate(prompt)
span.set_result(result.text)
span.set_llm_usage(
model="custom-model-v2",
prompt_tokens=result.usage.input,
completion_tokens=result.usage.output,
)
Performance
Auto-instrumentation adds:
- A few hundred microseconds per call for span creation and attribute setting — negligible next to an LLM call measured in hundreds of milliseconds.
- Memory for buffered spans, bounded by the batch processor.
- Network for periodic batch export, off the request path.
If you're tracing something extremely high-frequency — a vector database queried thousands of times a second — disable that instrumentor rather than accepting the span volume.
Related
- Manual Tracing — for code auto-instrumentation can't see
- Configuration — content capture, batching, pricing
- Agent Analytics — what agent framework spans populate