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

# Instrumentations

> Auto-instrumentation for AI providers and more

## What are Instrumentations?

Glass is built on [OpenTelemetry](https://opentelemetry.io/), the industry-standard for observability. OpenTelemetry uses **instrumentations** to automatically capture traces from libraries and frameworks — without you changing any code.

When you call `init()`, Glass automatically instruments your AI providers. Every API call is traced with request/response data, token usage, latency, and errors.

***

## Default Instrumentations

Glass automatically instruments these AI providers out of the box:

| Provider                 | Package               | What's Traced                               |
| ------------------------ | --------------------- | ------------------------------------------- |
| **OpenAI**               | `openai`              | Chat completions, embeddings, images, audio |
| **Anthropic**            | `anthropic`           | Messages, completions                       |
| **Google Generative AI** | `google-generativeai` | Gemini generate, chat, embeddings           |

<Info>
  Default instrumentations are enabled automatically. No configuration needed.
</Info>

```python theme={null}
from glass import init
from openai import OpenAI

init(api_key="your-api-key")

# This call is automatically traced
client = OpenAI()
response = client.chat.completions.create(
    model="gpt-4",
    messages=[{"role": "user", "content": "Hello!"}]
)
```

Each traced call captures:

* Request and response payloads
* Token usage (input/output/total)
* Model name and parameters
* Latency
* Errors and exceptions

***

## Adding Custom Instrumentations

Need to trace other libraries? You can add any OpenTelemetry-compatible instrumentation.

### Example: Adding HTTP Request Tracing

```python theme={null}
from glass import init
from opentelemetry.instrumentation.requests import RequestsInstrumentor

init(
    api_key="your-api-key",
    instrumentations=[RequestsInstrumentor()]
)
```

Now all `requests` library calls are traced alongside your AI calls.

### Example: Instrumenting Ollama

For local models served via [Ollama](https://ollama.com/), use the Ollama instrumentation:

```python theme={null}
from glass import init
from opentelemetry.instrumentation.ollama import OllamaInstrumentor

init(
    api_key="your-api-key",
    instrumentations=[OllamaInstrumentor()]
)

import ollama

# This call is automatically traced
response = ollama.chat(
    model="llama3",
    messages=[{"role": "user", "content": "Hello!"}]
)
```

Install it with `pip install opentelemetry-instrumentation-ollama`.

### Example: Multiple Custom Instrumentations

```python theme={null}
from glass import init
from opentelemetry.instrumentation.requests import RequestsInstrumentor
from opentelemetry.instrumentation.httpx import HTTPXClientInstrumentor
from opentelemetry.instrumentation.sqlalchemy import SQLAlchemyInstrumentor

init(
    api_key="your-api-key",
    instrumentations=[
        RequestsInstrumentor(),
        HTTPXClientInstrumentor(),
        SQLAlchemyInstrumentor(),
    ]
)
```

<Tip>
  Custom instrumentations are added **on top of** the defaults. Your AI providers are still traced automatically.
</Tip>

***

## Disabling Default Instrumentations

If you want full control over what gets instrumented, disable the defaults:

```python theme={null}
from glass import init
from opentelemetry.instrumentation.openai import OpenAIInstrumentor

init(
    api_key="your-api-key",
    skip_default_instrumentations=True,
    instrumentations=[
        OpenAIInstrumentor(),  # Only instrument OpenAI
    ]
)
```

***

## Popular GenAI Instrumentations

Here are commonly used instrumentations for AI/ML workflows:

| Library        | Instrumentation Package                    | Install                                                |
| -------------- | ------------------------------------------ | ------------------------------------------------------ |
| **LangChain**  | `opentelemetry-instrumentation-langchain`  | `pip install opentelemetry-instrumentation-langchain`  |
| **Ollama**     | `opentelemetry-instrumentation-ollama`     | `pip install opentelemetry-instrumentation-ollama`     |
| **LlamaIndex** | `opentelemetry-instrumentation-llamaindex` | `pip install opentelemetry-instrumentation-llamaindex` |
| **Cohere**     | `opentelemetry-instrumentation-cohere`     | `pip install opentelemetry-instrumentation-cohere`     |
| **Bedrock**    | `opentelemetry-instrumentation-bedrock`    | `pip install opentelemetry-instrumentation-bedrock`    |
| **Replicate**  | `opentelemetry-instrumentation-replicate`  | `pip install opentelemetry-instrumentation-replicate`  |
| **Pinecone**   | `opentelemetry-instrumentation-pinecone`   | `pip install opentelemetry-instrumentation-pinecone`   |
| **Chroma**     | `opentelemetry-instrumentation-chromadb`   | `pip install opentelemetry-instrumentation-chromadb`   |
| **Weaviate**   | `opentelemetry-instrumentation-weaviate`   | `pip install opentelemetry-instrumentation-weaviate`   |
| **Qdrant**     | `opentelemetry-instrumentation-qdrant`     | `pip install opentelemetry-instrumentation-qdrant`     |

<Card title="OpenTelemetry Registry" icon="book" href="https://opentelemetry.io/ecosystem/registry/?language=python&component=instrumentation">
  Browse all available Python instrumentations in the OpenTelemetry Registry.
</Card>
