OpenTelemetry openai instrumentation
Project description
opentelemetry-instrument-openai
It's OpenTelemetry instrumentation (python) for OpenAI's library.
Pproject site: https://github.com/cartermp/opentelemetry-instrument-openai-py
How to use it
Simple! First, install this package.
Autoinstrumentation
opentelemetry-bootstrap -a install
opentelemetry-instrument \
--traces_exporter console \
--metrics_exporter none \
--logs_exporter none \
python chat.py
If you're using poetry, put poetry run
before each command.
In code
It's one line of code too:
import openai
from dotenv import load_dotenv
from opentelemetry.instrument.openai import OpenAIInstrumentor
OpenAIInstrumentor().instrument()
load_dotenv()
openai.api_key = os.getenv("OPENAI_API_KEY")
openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=[{"role":"user", "content":"Tell me a joke about opentelemetry"}],
)
How to develop
Get poetry. Python build and dependency management is fucked but this is about as good as it gets.
Now install and run tests:
poetry install
poetry run pytest
Now you can develop and run tests as you go!
How to run the example
Click the example folder and read the README.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file opentelemetry_instrument_openai-0.2.0.tar.gz
.
File metadata
- Download URL: opentelemetry_instrument_openai-0.2.0.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.11.3 Darwin/22.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b8d23dbc6113b4a2c7f2d5e5e5c59becae0d73b721863c1704180b026ce7963 |
|
MD5 | 4cf2109c976596b7e2ec6929a5b56721 |
|
BLAKE2b-256 | 22a7853f6b2afc22121d32df83af1fbb319f448e62252395cf558a1cace3bf92 |
File details
Details for the file opentelemetry_instrument_openai-0.2.0-py3-none-any.whl
.
File metadata
- Download URL: opentelemetry_instrument_openai-0.2.0-py3-none-any.whl
- Upload date:
- Size: 10.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.5.1 CPython/3.11.3 Darwin/22.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0058487708d4d1c7cdf4cee8fbff9a8331a5243a85ff62b4769745a1835ae163 |
|
MD5 | d0e1782034322a41fd36742ba593acb1 |
|
BLAKE2b-256 | 8e0f62d07966c4efc7450b5e35e968be265f8a3c2b0eaee590b9ce11f550a929 |