OpenAI

OpenAI monitoring for LLM applications in production

by Obseria · AI and LLMs
  • OpenTelemetry
  • AI Observability
  • AI and LLMs
Category
AI and LLMs
Key metrics
9
Ready-made
5 dashboards & alerts
Setup
3 steps
Standard
OTLP

Instrument the OpenAI client with OpenTelemetry and Obseria turns every completion, embedding and tool call into a span with model, token counts and latency, connected to the request that triggered it.

Every call as a trace

Chat completions, responses, embeddings and tool calls appear as spans inside the trace of the user request, next to database queries and HTTP calls.

Tokens and cost per feature

Input and output tokens per model, service and endpoint show which feature drives spend, with budgets and anomaly alerts on top.

Open standard, no lock-in

The instrumentation follows the OpenTelemetry semantic conventions for GenAI, so the same data works with any OTLP backend.

Obseria interface

Obseria apps and capabilities: observability, APM, infrastructure and integrations
Obseria home dashboard with service health, open problems, SLO compliance and ingestion
Obseria trace explorer with span list and span attributes

Ready the moment data arrives

  • Model performance: calls, error rate and p95 per model
  • Token usage per service, model and endpoint
  • Alert on rising error rate or rate limiting
  • Alert on token spend anomalies against budget
  • Slowest OpenAI calls with the request that triggered them

OpenAI APIs and clients Obseria monitors

Chat Completions and Responses

Each call records the requested and returned model, finish reason, token usage and duration.

Embeddings

Embedding requests show up with model, input tokens and latency, which matters for RAG indexing jobs.

Tool and function calls

Tool calls requested by the model are visible on the span, so agent loops can be followed step by step.

Streaming responses

Streamed completions are traced from request to the last chunk, so you see the real end-to-end duration.

Python and Node.js SDKs

Instrumentation packages exist for the official openai libraries in both languages.

Azure OpenAI and compatible endpoints

The same OpenAI instrumentation traces Azure OpenAI and other services that speak the OpenAI protocol.

The OpenAI signals that matter

Obseria collects these values automatically and shows them in ready-made dashboards and alerts.

MetricUnitWhat it tells you
gen_ai.client.operation.durationsHistogram of model call duration per model and operation, the core latency signal for LLM features.
gen_ai.client.token.usage{token}Histogram of tokens per call, split into input and output via gen_ai.token.type.
gen_ai.request.modelSpan attribute with the model you asked for; Obseria groups calls, errors and latency by it.
gen_ai.response.modelSpan attribute with the model version that actually answered, useful when aliases move to new snapshots.
gen_ai.usage.input_tokens{token}Span attribute with the prompt tokens of one call; long system prompts and large contexts show up here.
gen_ai.usage.output_tokens{token}Span attribute with the generated tokens of one call, usually the bigger driver of latency.
gen_ai.operation.nameSpan attribute such as chat or embeddings, to separate interactive calls from batch workloads.
gen_ai.response.finish_reasonsWhy generation stopped, for example stop, length or tool_calls; length points to truncated answers.
error.typeError class of failed calls, for example rate limits, timeouts or invalid requests.

Set up OpenAI monitoring in minutes

  1. 1

    Install the instrumentation

    Add traceloop-sdk and opentelemetry-instrumentation-openai with pip, or @traceloop/node-server-sdk with npm for Node.js.

  2. 2

    Point the exporter at Obseria

    Set TRACELOOP_BASE_URL to your Obseria OTLP endpoint and TRACELOOP_HEADERS to your token; set TRACELOOP_TRACE_CONTENT=false if prompts must not leave the process.

  3. 3

    Initialize before the first call

    Call Traceloop.init before the OpenAI client is imported, make one request and open Model Performance in Obseria.

Example configuration · PYTHON
# pip install traceloop-sdk opentelemetry-instrumentation-openai
#
# Environment (set in your deployment):
#   TRACELOOP_BASE_URL=${OBSERIA_OTLP_ENDPOINT}
#   TRACELOOP_HEADERS=Authorization=Bearer%20${OBSERIA_TOKEN}
#   TRACELOOP_TRACE_CONTENT=false   # keep prompts and completions out of spans
#   OTEL_SERVICE_NAME=support-assistant
from traceloop.sdk import Traceloop

# Initialize before the OpenAI client is imported and used.
Traceloop.init(app_name="support-assistant", disable_batch=False)

from openai import OpenAI

client = OpenAI()  # reads OPENAI_API_KEY
response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[{"role": "user", "content": "Summarize ticket 4711"}],
)
# The call becomes a span with gen_ai.request.model,
# gen_ai.usage.input_tokens, gen_ai.usage.output_tokens and latency.

Why OpenAI monitoring matters

Once an OpenAI model is part of a product, it behaves like any other critical dependency, only less predictable. The same prompt can produce answers of very different length, a model alias can move to a new snapshot, and rate limits apply per organization rather than per service. Latency is dominated by the number of generated tokens, and cost grows with every token you send and receive. Without OpenAI monitoring, teams notice these effects through user complaints or an unexpected invoice.

LLM monitoring with OpenTelemetry treats each model call as a span. The span carries the requested and returned model, token counts, finish reason and errors, and it sits inside the trace of the request that triggered it. That makes it possible to answer practical questions: which endpoint sends the largest prompts, which model version is slowest, and whether a slowdown comes from OpenAI, from retrieval or from your own code.

Signals that matter for OpenAI API monitoring

The OpenTelemetry semantic conventions for generative AI define a small, consistent set of signals that work across providers:

  • Latency: gen_ai.client.operation.duration per model and operation. Look at p95 rather than averages, because a few long completions dominate user experience.
  • Token usage: gen_ai.client.token.usage and the span attributes gen_ai.usage.input_tokens and gen_ai.usage.output_tokens. Input tokens reveal oversized contexts, output tokens explain latency.
  • Model: gen_ai.request.model and gen_ai.response.model. Comparing both shows when an alias resolves to a different version.
  • Outcome: gen_ai.response.finish_reasons and error.type. A rising share of length means answers are cut off; rate-limit errors mean you are close to your quota.

Obseria reads these attributes directly. Model Performance lists every model with calls, error rate, weighted p95 and input and output tokens, and AI Observability adds token cost per model, feature and tenant.

Common OpenAI production problems and how to detect them

Rate limits and retries

When traffic grows, requests start to fail with rate-limit errors and SDK retries add latency. In traces this shows up as repeated client spans for the same operation and a rising error rate on one model. An alert on errors per model catches it before users do.

Growing prompts

Conversation history, retrieved documents and verbose system prompts make prompts grow over time. Input tokens per endpoint rising week over week is the signal, and the trace shows which step adds the context.

Slow answers after a change

A new model, a new prompt template or a higher max_tokens setting can double response time without any error. Comparing duration and output tokens per service.version right after a deployment separates a real regression from normal variation.

Cost spikes

A loop in an agent, a batch job without limits or a feature that suddenly gets popular can multiply token usage. Anomaly detection on token usage per service flags the change early, and the trace shows which code path is responsible.

Prompts, responses and personal data

Prompts and completions often contain personal or confidential data. Decide deliberately what leaves your process. OpenLLMetry records prompt and completion content on spans by default; set TRACELOOP_TRACE_CONTENT=false to send only metadata such as model, token counts and duration. The official OpenTelemetry package opentelemetry-instrumentation-openai-v2 works the other way round: content capture is off unless you set OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=true. If you do store content, Obseria can keep it in full, masked or only as a hash, detects and masks personal data, and keeps data in the EU.

Best practices for LLM monitoring with OpenAI

  1. Initialize instrumentation before the OpenAI client is imported, otherwise calls are not patched.
  2. Set service.name, service.version and deployment.environment.name so model behavior can be compared across releases and environments.
  3. Pin model snapshots in production and watch gen_ai.response.model to see when they change.
  4. Add your own attributes for feature or tenant, so token usage can be attributed to the part of the product that causes it.
  5. Alert on error rate and p95 per model, and on token usage anomalies per service.

How Obseria helps with OpenAI monitoring

Obseria receives OpenAI spans over OTLP and shows them in the same traces as your HTTP requests, databases and queues. Model Performance compares models by calls, error rate, latency and tokens. AI Observability adds token cost per model, feature and tenant with budgets and anomaly alerts, and guardrails and evaluations can score response quality. When an LLM feature slows down, Obseria Intelligence correlates model latency, retries, deployments and upstream changes and presents the root cause with its chain of evidence. All data stays exportable via OTLP.

Learn more

OpenAI monitoring FAQ

Only a few lines at startup. You install the instrumentation package and call Traceloop.init before the OpenAI client is used. Every later call is traced automatically.

The Obseria setup guide uses OpenLLMetry (traceloop-sdk with opentelemetry-instrumentation-openai) for Python and Node.js. The OpenTelemetry project also maintains opentelemetry-instrumentation-openai-v2. Both follow the GenAI semantic conventions and send standard OTLP data.

That is your choice. With OpenLLMetry, set TRACELOOP_TRACE_CONTENT=false to send only metadata. With the v2 package, content stays off unless you enable it. Stored content can be masked or hashed in Obseria.

Yes. Azure OpenAI speaks the OpenAI protocol, so the same instrumentation traces it. Spans carry your Azure deployment name.

Yes. Obseria shows token cost per model, service, feature and tenant in AI Observability and lets you set budgets and anomaly alerts on it.

No. The instrumentation runs in your application and only observes the calls it makes. Obseria has no access to your OpenAI account or API key.

Start monitoring OpenAI today

Connect OpenAI in minutes with OpenTelemetry or the Obseria Agent. Free for 14 days.