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:
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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| openai_otel-0.1.0a3.tar.gz | 3.5 kB | Without provenance | Details for openai_otel-0.1.0a3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| openai_otel-0.1.0a3-py3-none-any.whl | Python 3 | none | any | Details for openai_otel-0.1.0a3-py3-none-any.whl |
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
|
Security for openai-otel 0.1.0a3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.