Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

OpenAI OTEL

OpenAI OTEL is a library that allows you to instrument your OpenAI Python client using OpenTelemetry.

Installation

pip install openai-otel

Or

poetry add openai-otel

if you are using poetry.

Usage

Make sure that you have OPENAI_API_KEY set in your environment variables.

import openai
from openai_otel import OpenAIAutoInstrumentor, tracer
from opentelemetry import trace
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import SimpleSpanProcessor, ConsoleSpanExporter

trace.set_tracer_provider(TracerProvider())
trace.get_tracer_provider().add_span_processor(
    SimpleSpanProcessor(ConsoleSpanExporter())
)

OpenAIAutoInstrumentor().instrument()

resp = openai.chat.completions.create(
    model="gpt-4o",
    messages=[
        {"role": "user", "content": "what's the meaning of life?"},
    ],
)

print(resp.choices[0].message.content)

Examples

Start up tempo using docker compose:

(
    cd examples/tempo
    docker compose up -d
)

Run the example:

(
    cd examples/fastapi
    pip install -r requirements.txt
    fastapi run
)

Then open http://localhost:8000 - you shall get the meaning of life.

Afterwards you can check out the traces on Grafana. You can do it via:

  • Visit http://localhost:3000
  • Go to the explorer view
  • Click TraceQL
  • Run {.service.name="fastapi-demo" && span.create.request.model="gpt-4o"}

More examples

You will get view like this:

alt text

Metadata

Release files for openai-otel 0.1.0a3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for openai-otel 0.1.0a3
File Size Uploaded
openai_otel-0.1.0a3.tar.gz 3.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for openai-otel 0.1.0a3
File Interpreter ABI Platform
openai_otel-0.1.0a3-py3-none-any.whl Python 3 none any Details

Total release size: 7.4 kB

Release files / openai_otel-0.1.0a3.tar.gz

Download URL openai_otel-0.1.0a3.tar.gz
Size 3.5 kB
Tags Source
SHA-256 checksum
How to use checksums
12969c3055b55027aa86b9854de8ccfabb014f55f2b37796d2d2d1672190d6a0
BLAKE2b-256 checksum
How to use checksums
a4c5d110462a74e08f32549fe32e8802554934bdab719b0636010c22bd0c2cc2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.6 Linux/6.8.0-1014-azure

Release files / openai_otel-0.1.0a3-py3-none-any.whl

Download URL openai_otel-0.1.0a3-py3-none-any.whl
Size 4.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1dc52e6d7a4933319bd3650bf7207cc8e819a868d8ed183beda1547f4b417928
BLAKE2b-256 checksum
How to use checksums
76f83c2bd8156843ad5e5a5a4e43ae9e989aa4a01d7f839dda415916c6cc24b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.3 CPython/3.12.6 Linux/6.8.0-1014-azure
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page