opentelemetry-instrumentation-openai-v2
OpenTelemetry Official OpenAI instrumentation
What it is and what it does
This package integrates OpenTelemetry tracing into applications using the OpenAI Python SDK or compatible LLM platforms. When installed and initialized, it automatically captures spans for chat completions, embeddings, and other API operations, recording metrics like token usage and operation duration. It works with OpenAI-compatible services including Azure OpenAI, Gemini, Perplexity, xAI, DeepSeek, Groq, and MistralAI when accessed through the OpenAI SDK.
The instrumentation is configured via environment variables to control what telemetry is captured—by default it traces operations without capturing message content, but you can enable content logging as events or span attributes. It requires an existing OpenTelemetry setup (tracing, logging, and events configured) to emit the captured telemetry. The package is in Beta status and aligns with OpenTelemetry Semantic Conventions v1.30.0, with experimental features available through opt-in environment variables.
Use it for:
- Monitor and debug OpenAI API calls in production applications by viewing traces of chat completions and embeddings.
- Track token consumption across LLM operations for cost analysis and quota management.
- Correlate LLM requests with other application traces in a centralized observability platform.
- Audit and log prompt and completion content when compliance or debugging requires it.
- Observe applications using OpenAI-compatible services (Groq, Gemini, etc.) with a single instrumentation.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Automatically traces and logs OpenAI API calls (and compatible platforms like Azure OpenAI, Gemini, Groq) with OpenTelemetry, capturing request spans, token counts, and operation duration.
Yes, if you already have OpenTelemetry configured in your application and need visibility into OpenAI or compatible LLM API calls. The low install friction, active maintenance, permissive license, and zero known vulnerabilities make it safe to adopt. Not necessary if you have no OpenTelemetry setup or do not use the OpenAI SDK.
Install
opentelemetry-instrumentation-openai-v2 on PyPI
pip
pip install opentelemetry-instrumentation-openai-v2uv
uv add opentelemetry-instrumentation-openai-v2poetry
poetry add opentelemetry-instrumentation-openai-v2Installing opentelemetry-instrumentation-openai-v2
Before you install
Low friction installation with four stable OpenTelemetry dependencies already in the ecosystem. Active maintenance (last commit 2026-08-14) and no known vulnerabilities. Requires Python 3.10 or later.
License in practice
Apache-2.0 permissive license allows use in most commercial and open-source projects without significant restrictions.
Quickstart
pip install opentelemetry-instrumentation-openai-v2
from opentelemetry.instrumentation.openai_v2 import OpenAIInstrumentor
from openai import OpenAI
OpenAIInstrumentor().instrument()
client = OpenAI()
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "Hello"}]
)
Requires OpenTelemetry tracing, logging, and events to be configured before instrumentation will emit telemetry. Requires Python 3.10 or later.
Verify before relying
- Whether the package works with all listed OpenAI-compatible platforms (Azure OpenAI, Gemini, Perplexity, xAI, DeepSeek, Groq, MistralAI) equally well or if some have limitations.
- Performance overhead of instrumentation on high-volume LLM applications.
- Whether the optional upload hook for prompts/completions (requiring fsspec) is production-ready.
Package facts
| License | Apache-2.0 (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 4 — opentelemetry-api, opentelemetry-instrumentation, opentelemetry-semantic-conventions, opentelemetry-util-genai |
| Maintenance | actively maintained — 105 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 1,897,611/month — #3,447 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: opentelemetry_instrumentation_openai_v2-2.4b0-py3-none-any.whl
Tags
More Monitoring packages
Wraps any iterable to display a real-time…
copyleft · top 100 on PyPI
opentelemetry-semantic-conventionsProvides generated Python code for…
permissive · top 100 on PyPI
opentelemetry-sdkProvides the reference implementation of the…
permissive · top 100 on PyPI
opentelemetry-apiProvides the abstract API and interfaces for…
permissive · top 100 on PyPI
opentelemetry-exporter-otlp-proto-httpExports OpenTelemetry observability data to an…
permissive · top 1,000 on PyPI
opentelemetry-instrumentationProvides automatic instrumentation commands and…
permissive · top 1,000 on PyPI
opentelemetry-instrumentation-google-genaiAdds OpenTelemetry instrumentation to the…
permissive · top 5,000 on PyPI
opentelemetry-instrumentation-openaiCaptures traces of OpenAI API calls (prompts,…
permissive · top 5,000 on PyPI
opentelemetry-instrumentation-openai-agents-v2Automatically captures telemetry data from…
permissive · top 5,000 on PyPI
langwatchLangWatch is a Python SDK for instrumenting and…
permissive · top 15,000 on PyPI
loongsuite-util-genaiExtends OpenTelemetry's GenAI semantic…
permissive · top 5,000 on PyPI
opentelemetry-util-genaiProvides standardized instrumentation utilities…
permissive · top 5,000 on PyPI
opentelemetry-semantic-conventions-aiProvides OpenTelemetry semantic conventions and…
permissive · top 1,000 on PyPI
opentelemetry-instrumentation-groqAutomatically captures traces of Groq SDK API…
permissive · top 5,000 on PyPI
opentelemetry-instrumentation-google-generativeaiAutomatically traces prompts, completions, and…
permissive · top 5,000 on PyPI
openinference-instrumentation-portkeyAutomatically instruments Portkey AI API calls…
permissive · top 15,000 on PyPI