---
title: LLM Applications
description: "Monitor, trace, and debug LLM apps in production with OpenObserve and OpenTelemetry: track token usage, latency, cost, model metadata, and errors per call."
---

# LLM Observability with OpenObserve

Monitor, trace, and debug your LLM-powered applications in production using OpenObserve and OpenTelemetry.

> **Note**: LLM Observability is available on both OpenObserve Cloud and self-hosted deployments.

## What is LLM Observability?

LLM Observability gives you visibility into the behaviour of large language model calls inside your application , similar to traditional APM, but purpose-built for AI workloads.

With it you can track:

* **Token usage**: prompt, completion, and total tokens per request  
* **Latency** : end-to-end duration of every LLM call  
* **Model metadata** : model name, temperature, max tokens, and other parameters  
* **Errors** : rate limit events, API failures, and timeouts with full context

**Under the hood:** LLM Observability is OpenTelemetry. There is nothing special about LLM traces compared to regular distributed traces, the work happens on the server side. Any OpenTelemetry-compatible SDK or exporter can ship traces to OpenObserve.

## Prerequisites

* Python 3.9+  
* [`uv`](https://github.com/astral-sh/uv) package manager (or `pip`)  
* An [OpenObserve](https://openobserve.ai/) account (cloud or self-hosted)  
* Your OpenObserve **organisation ID** and **auth token**, copied from **Data** > **Data sources** > **Custom** > **Traces** > **OpenTelemetry** in the OpenObserve UI

## Configuration

Go to **Data** > **Data sources** > **Custom** > **Traces** > **OpenTelemetry** in the OpenObserve UI and copy the endpoint and the **Authorization** header value under **OTLP HTTP**. `OPENOBSERVE_URL` is the part of the endpoint before `/api/`; the SDK adds `/api/<org>/v1/traces` itself.

![Data sources > Custom > Traces > OpenTelemetry with the OTLP HTTP collector config](../../images/opentelemetry-collector-for-traces-v2.png)

Create a `.env` file in your project root:

```
# OpenObserve instance URL
# Default for self-hosted: http://localhost:5080
OPENOBSERVE_URL=https://api.openobserve.ai/

# Your OpenObserve organisation slug or ID
OPENOBSERVE_ORG=your_org_id

# Auth token: copy the Authorization header value from Data > Data sources > Custom > Traces > OpenTelemetry
OPENOBSERVE_AUTH_TOKEN="Basic <token_from_ui>"

# Enable or disable tracing (default: true)
OPENOBSERVE_ENABLED=true

# API keys for services you're using (optional, based on instrumentation)
OPENAI_API_KEY="your-openai-key"
ANTHROPIC_API_KEY="your-anthropic-key"
```

The **OTEL Collector** tab next to it shows the same endpoint and `Authorization` header in a collector configuration.

![Data sources > Custom > Traces > OpenTelemetry with the endpoint and Authorization header for the collector](../../images/opentelemetry-collector-for-traces-v2.png)

| Variable | Description | Required |
| ----- | ----- | ----- |
| `OPENOBSERVE_URL` | Base URL of your OpenObserve instance | Yes |
| `OPENOBSERVE_ORG` | Organisation slug or ID | Yes |
| `OPENOBSERVE_AUTH_TOKEN` | Authorization header value from **Data** > **Data sources** > **Custom** > **Traces** > **OpenTelemetry** (`Basic <token>`) | Yes |
| `OPENOBSERVE_ENABLED` | Toggle tracing on/off | No (default: `true`) |
| `OPENOBSERVE_TRACES_STREAM_NAME` | Traces stream to write to | No (default: `default`) |
| `OPENAI_API_KEY` | Only needed by the bundled OpenAI example | No |

## Option A : Quickstart with the bundled example

Clone the SDK repository and run the included OpenAI example to see traces flowing into OpenObserve with minimal setup.

**1\. Clone the repository**

```shell
git clone https://github.com/openobserve/openobserve-python-sdk/
cd openobserve-python-sdk
```

**2\. Install dependencies**

```shell
uv pip install openobserve-python-sdk openai opentelemetry-instrumentation-openai python-dotenv
uv pip install -r requirements.txt
```

**3\. Add your `.env` file** to the project root (see Configuration above), including `OPENAI_API_KEY`.

**4\. Run the example**

```shell
uv run examples/openai_example.py
```

Open **Traces** in OpenObserve to see the spans appear.

![Traces list for an LLM service with Input Tokens, Output Tokens, and Cost columns](../images/llm-applications/llm-tokens-cost-latency-v2.png)


## Option B: Integrate into your own project using the OpenObserve SDK

Use this if you want the simplest possible integration without cloning the repository.

**1\. Install dependencies**

```shell
uv pip install openobserve-python-sdk opentelemetry-instrumentation-openai python-dotenv
```

**2\. Initialise the SDK at your application entry point and  Use your LLM client as normal**

Sample OpenAI Instrumentation:

```python
from opentelemetry.instrumentation.openai import OpenAIInstrumentor
from openobserve import openobserve_init

# Initialize OpenObserve and instrument OpenAI
OpenAIInstrumentor().instrument()
openobserve_init()

from openai import OpenAI

# Use OpenAI as normal - traces are automatically captured
client = OpenAI()
response = client.chat.completions.create(
    model="gpt-3.5-turbo",
    messages=[{"role": "user", "content": "Hello!"}]
)
print(response.choices[0].message.content)

```

Sample Anthropic Instrumentation:
```python
from opentelemetry.instrumentation.anthropic import AnthropicInstrumentor
from openobserve import openobserve_init

# Initialize OpenObserve and instrument Anthropic
AnthropicInstrumentor().instrument()
openobserve_init()

from anthropic import Anthropic

# Use Claude as normal - traces are automatically captured
client = Anthropic()
response = client.messages.create(
    model="claude-3-5-sonnet-20241022",
    max_tokens=1024,
    messages=[{"role": "user", "content": "Hello!"}]
)
print(response.content[0].text)

```
Every call is now captured as a trace span and exported to OpenObserve.

Note: The **openobserve-python-sdk** is an optional thin wrapper around the standard OpenTelemetry Python SDK that simplifies setup and exporter configuration. If you already use OpenTelemetry, you can send telemetry directly to the OpenObserve OTLP endpoint without it.

## Option C: Instrument with a coding agent

Let a coding agent such as Claude Code, Cursor, or Codex add the instrumentation to your project.

1. Go to **Data** > **Data sources** > **AI Integrations** and open your provider or framework.
2. Open the **With a coding agent** tab.
3. Optionally change the **Traces Stream Name**.
4. Click **Download .env** and save it in your project root, so the token stays out of the chat.
5. Copy the **Prompt** into your coding agent; this starts the check for the first span.
6. Let the agent run one sample request. If no span arrives in 15 minutes, the status shows what went wrong.

When the first span arrives, the tab runs the **AI data health** checks:

| Check | What it flags |
| ----- | ----- |
| **Unpriced models** | Models without a price, whose spans count as $0. Shown only when model pricing is enabled. |
| **Missing agent identity** | LLM spans without `gen_ai.agent.name`, which agent views miss. |
| **Zero-duration spans** | LLM spans that report 0 ms, so latency reads too low. |
| **Spans without session id** | LLM spans without `gen_ai.conversation.id`, which Sessions misses. |

A failing check lists sample traces. After the agent fixes the code and runs another request, click **Check again**.

## What gets captured

The `opentelemetry-instrumentation-openai` library attaches request, response, and token attributes to each span. OpenObserve stores attribute names with dots replaced by underscores, for example:

| Attribute | Description |
| ----- | ----- |
| `gen_ai_request_model` | Requested model (e.g. `gpt-4o`) |
| `gen_ai_response_model` | Model version that served the response |
| `gen_ai_usage_input_tokens` | Tokens in the prompt |
| `gen_ai_usage_output_tokens` | Tokens in the response |
| `duration` | End-to-end request latency |
| `error` | Exception details if the request failed |

See [OpenAI (Python)](providers/openai.md#what-gets-captured) for the full list.

In addition, OpenObserve computes and stores the following token and cost fields on each LLM span at ingestion:

| Field | Type | Description |
| ----- | ----- | ----- |
| `gen_ai_operation_name` | Utf8 | Operation type, for example `chat` or `embeddings` |
| `gen_ai_usage_input_tokens` | Int64 | Input (prompt) tokens |
| `gen_ai_usage_output_tokens` | Int64 | Output (completion) tokens |
| `gen_ai_usage_total_tokens` | Int64 | Total tokens consumed |
| `gen_ai_usage_cost_input` | Float64 | Cost of input tokens |
| `gen_ai_usage_cost_output` | Float64 | Cost of output tokens |
| `gen_ai_usage_cost` | Float64 | Total cost of the LLM call |

The cost fields are filled from the span's own reported cost when it has one; otherwise [Model Pricing](model-pricing.md) calculates them from the model name and token counts (`ZO_MODEL_PRICING_ENABLED`, on by default). A span whose model has no price keeps its token counts but gets no cost fields, rather than a zero cost. Spans with prompt caching also get `gen_ai_usage_cache_read_input_tokens`, `gen_ai_usage_cache_creation_input_tokens`, and matching `gen_ai_usage_cost_cache_*` fields.

## Viewing traces in OpenObserve

1. Log in to your OpenObserve instance  
2. Navigate to **Traces** in the left sidebar  
3. Filter by service name, model, or time range
![Traces filtered by service name on the LLM traces stream](../images/llm-applications/llm-traces-v2.png)

4. Click any span to inspect token counts, latency, and full request metadata

![Trace Waterfall with an openai.chat span selected, showing its input and output messages](../images/llm-applications/llm-spans-v2.png)

![Attributes table of an openai.chat span with gen_ai token and cost fields](../images/llm-applications/llm-span-attributes-v2.png)



## Troubleshooting

**Traces are not appearing in OpenObserve**

* Confirm `OPENOBSERVE_ENABLED=true` in your `.env`  
* Check that `OPENOBSERVE_URL` is the base URL of your instance, without `/api/<org>`  
* Verify `OPENOBSERVE_AUTH_TOKEN` matches the Authorization header value from **Data** > **Data sources** > **Custom** > **Traces** > **OpenTelemetry** (`Basic <token>`)  
* Ensure the SDK or tracer provider is initialised before any LLM calls

**`ModuleNotFoundError: No module named 'dotenv'`**

* Install the correct package: `uv pip install python-dotenv` (not `dotenv`)

**`ModuleNotFoundError: No module named 'openobserve'`**

* Run: `uv pip install openobserve-python-sdk`

## Read More
- [OpenObserve Python SDK](https://openobserve.ai/docs/user-guide/data-processing/opentelemetry/openobserve-python-sdk/)
- [LLM Evaluations](https://openobserve.ai/docs/integration/ai/llm-evaluations/): Continuously score live LLM traces using LLM-as-a-judge or remote scorers.
- [LLM Experiments](https://openobserve.ai/docs/integration/ai/llm-experiments/): Run offline, batch evaluations against versioned datasets and compare results.
