> ## Documentation Index
> Fetch the complete documentation index at: https://docs.getnetra.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Auto Instrumentation

> Automatically capture traces from OpenAI, LangChain, Pinecone, and 30+ providers with Netra auto-instrumentation. Zero code changes required.

Auto-instrumentation is the easiest way to start tracing your AI applications. When you call `Netra.init()`, the SDK automatically instruments a **curated default set** of AI-relevant libraries in your application—covering LLM providers, agent frameworks, vector databases, and key web frameworks—capturing traces without requiring any code changes.

<Note>
  Netra does **not** instrument every library in your environment by default. Only a curated set of AI-relevant libraries (`DEFAULT_INSTRUMENTS`) is enabled out of the box. See [Selective Instrumentation](#selective-instrumentation) for details.
</Note>

## 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:

1. Creates a span for the operation
2. Captures input parameters (prompts, queries, etc.)
3. Records output data (completions, results, etc.)
4. Measures latency and performance metrics
5. 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:

<CodeGroup>
  ```python Python theme={null}
  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
  ```

  ```typescript TypeScript theme={null}
  import { Netra } from "netra-sdk";

  // Initialize before importing other libraries for best results
  await Netra.init({
    appName: "my-ai-app",
    environment: "production",
  });

  // Your existing code works unchanged
  import OpenAI from "openai";

  const client = new OpenAI();
  const response = await client.chat.completions.create({
    model: "gpt-4",
    messages: [{ role: "user", content: "Hello!" }],
  });
  // This call is automatically traced
  ```
</CodeGroup>

<Note>
  For best results, initialize Netra before importing the libraries you want to instrument. This ensures all calls are captured from the start.
</Note>

## 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:

<CodeGroup>
  ```python Python theme={null}
  Netra.init(
      app_name="my-ai-app",
      trace_content=False,  # Disable prompt/completion capture
  )
  ```

  ```typescript TypeScript theme={null}
  await Netra.init({
    appName: "my-ai-app",
    traceContent: false, // Disable prompt/completion capture
  });
  ```
</CodeGroup>

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**](https://docs.getnetra.ai/Observability/Traces/configuration/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:

<CodeGroup>
  ```python Python theme={null}
  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}],
      )
  ```

  ```typescript TypeScript theme={null}
  import { Netra } from "netra-sdk";
  import OpenAI from "openai";

  await Netra.init({ appName: "my-ai-app" });

  const client = new OpenAI();

  // Create a parent span for your workflow
  const span = Netra.startSpan("process-user-query");
  span.setAttribute("user.query", userQuery);

  // Auto-instrumented OpenAI call appears as a child span
  const response = await client.chat.completions.create({
    model: "gpt-4",
    messages: [{ role: "user", content: userQuery }],
  });

  span.end();
  ```
</CodeGroup>

## Supported Instrumentations

Netra supports a wide range of libraries across both Python and TypeScript. For detailed integration guides, see the [Integrations](/Integrations/overview) 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` | -                      |
| ADK         | `google-adk`  | -                      |
| Agno        | `agno`        | -                      |

### 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

* [Decorators](/Observability/Traces/decorators) - Add semantic context with `@workflow`, `@agent`, and `@task`
* [Manual Tracing](/Observability/Traces/manual-tracing) - Create custom spans for fine-grained control
* [Instrumentation Selection](/Observability/Traces/configuration/instrumentation-selection) - Control which libraries are instrumented
