Auto-instrumentation is the easiest way to start tracing your AI applications. When you call Netra.init(), the SDK automatically detects and instruments supported libraries in your application, capturing traces without requiring any code changes.
How It Works
Netra uses monkey-patching to intercept calls to supported libraries at runtime. When your application makes a call to an LLM provider, vector database, or HTTP client, Netra automatically:
- Creates a span for the operation
- Captures input parameters (prompts, queries, etc.)
- Records output data (completions, results, etc.)
- Measures latency and performance metrics
- Tracks token usage and costs (for LLM calls)
All of this happens transparently without modifying your existing code.
Quick Start
Initialize Netra at the start of your application to enable auto-instrumentation:
from netra import Netra
# Initialize before importing other libraries for best results
Netra.init(app_name="my-ai-app", environment="production")
# Your existing code works unchanged
from openai import OpenAI
client = OpenAI()
response = client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": "Hello!"}],
)
# This call is automatically traced
For best results, initialize Netra before importing the libraries you want to instrument. This ensures all calls are captured from the start.
What Gets Captured
For each instrumented call, Netra captures relevant attributes based on the operation type:
LLM Calls
| Attribute | Description |
|---|
gen_ai.system | The LLM provider (e.g., “openai”, “anthropic”) |
gen_ai.request.model | Model name used for the request |
gen_ai.prompt | Input prompt (if trace_content is enabled) |
gen_ai.completion | Generated response (if trace_content is enabled) |
gen_ai.usage.prompt_tokens | Number of input tokens |
gen_ai.usage.completion_tokens | Number of output tokens |
gen_ai.usage.total_tokens | Total tokens used |
Vector Database Operations
| Attribute | Description |
|---|
db.system | Database type (e.g., “pinecone”, “qdrant”) |
db.operation | Operation type (e.g., “query”, “upsert”) |
db.vector.query.top_k | Number of results requested |
HTTP Requests
| Attribute | Description |
|---|
http.method | HTTP method (GET, POST, etc.) |
http.url | Request URL |
http.status_code | Response status code |
http.request.body | Request body (if enabled) |
http.response.body | Response body (if enabled) |
Controlling Content Capture
By default, Netra captures prompt and completion content. You can disable this for privacy or compliance reasons:
Netra.init(
app_name="my-ai-app",
trace_content=False, # Disable prompt/completion capture
)
When trace_content is disabled, Netra still captures:
- Token counts and usage metrics
- Latency and performance data
- Model names and configuration
- Error information
Selective Instrumentation
You can control which libraries are instrumented. See Instrumentation Selection for details on:
- Enabling only specific instrumentations
- Blocking certain instrumentations
- Fine-tuning what gets captured
Combining with Manual Tracing
Auto-instrumentation works seamlessly with manual tracing. You can add custom spans and attributes to provide additional context:
from netra import Netra
from openai import OpenAI
Netra.init(app_name="my-ai-app")
client = OpenAI()
# Create a parent span for your workflow
with Netra.start_span("process-user-query") as span:
span.set_attribute("user.query", user_query)
# Auto-instrumented OpenAI call appears as a child span
response = client.chat.completions.create(
model="gpt-4",
messages=[{"role": "user", "content": user_query}],
)
Supported Instrumentations
Netra supports a wide range of libraries across both Python and TypeScript. For detailed integration guides, see the Integrations section.
LLM Providers
Automatically trace completions, embeddings, and other API calls to major LLM providers.
| Provider | Python | TypeScript |
|---|
| OpenAI | openai | openai |
| Anthropic | anthropic | - |
| Google Generative AI | google-generativeai | @google/generative-ai |
| Cohere | cohere | - |
| Mistral | mistralai | @mistralai/mistralai |
| Groq | groq | groq-sdk |
| AWS Bedrock | boto3 | - |
| Vertex AI | google-cloud-aiplatform | @google-cloud/vertexai |
| Ollama | ollama | - |
| Replicate | replicate | - |
| Together AI | together | together-ai |
| Hugging Face | transformers | - |
| LiteLLM | litellm | - |
AI Frameworks
Capture chain executions, agent steps, and tool calls from popular AI orchestration frameworks.
| Framework | Python | TypeScript |
|---|
| LangChain | langchain | langchain |
| LangGraph | langgraph | @langchain/langgraph |
| LlamaIndex | llama-index | llamaindex |
| Haystack | haystack | - |
| CrewAI | crewai | - |
| DSPy | dspy | - |
| Pydantic AI | pydantic-ai | - |
Vector Databases
Track similarity searches, upserts, and other vector operations for RAG pipelines.
| Database | Python | TypeScript |
|---|
| Pinecone | pinecone-client | @pinecone-database/pinecone |
| Weaviate | weaviate-client | - |
| Qdrant | qdrant-client | @qdrant/js-client-rest |
| ChromaDB | chromadb | chromadb |
| Milvus | pymilvus | - |
| LanceDB | lancedb | - |
| Marqo | marqo | - |
Web Frameworks
Instrument incoming HTTP requests to trace your API endpoints end-to-end.
| Framework | Python | TypeScript |
|---|
| FastAPI | fastapi | - |
| Flask | flask | - |
| Django | django | - |
| Starlette | starlette | - |
| Express | - | express |
| Fastify | - | fastify |
| NestJS | - | @nestjs/core |
HTTP Clients
Capture outgoing HTTP requests to external services and APIs.
| Client | Python | TypeScript |
|---|
| HTTPX | httpx | - |
| AIOHTTP | aiohttp | - |
| Requests | requests | - |
| urllib3 | urllib3 | - |
| Fetch | - | Built-in |
| HTTP/HTTPS | - | Built-in |
Databases
Monitor database queries and operations for performance analysis.
| Database | Python | TypeScript |
|---|
| PostgreSQL | psycopg2, psycopg | pg |
| MySQL | pymysql | mysql2 |
| MongoDB | pymongo | mongodb |
| Redis | redis | redis, ioredis |
| SQLAlchemy | sqlalchemy | - |
| SQLite | sqlite3 | - |
| Elasticsearch | elasticsearch | - |
| Prisma | - | @prisma/client |
| TypeORM | - | typeorm |
Message Queues
Trace asynchronous task processing and message-based workflows.
| Queue | Python | TypeScript |
|---|
| Celery | celery | - |
| RabbitMQ | pika, aio-pika | amqplib |
| Kafka | kafka-python, confluent-kafka | kafkajs |
| AWS SQS | boto3 | - |
Next Steps