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.
Usage
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"}],
)
You can then run your app normally with your own opentelemetry initialization, or use the the autoinstrumentation agent (remove poetry run
if you're not using poetry).
poetry run opentelemetry-bootstrap -a install
poetry run opentelemetry-instrument \
--traces_exporter console \
--metrics_exporter none \
--logs_exporter none \
python chat.py
How to develop
Get poetry.
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.3.0.tar.gz
.
File metadata
- Download URL: opentelemetry_instrument_openai-0.3.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 | 21a0c52ae36dfc80055d7749a9edb1a547e1f4409c75f8d59eb8e29b57110d18 |
|
MD5 | ba539d495a69242c4fbef44ea10d1425 |
|
BLAKE2b-256 | 0a5401d3496aa73d8d32a632fde1d95f3cb89dd41eee2cfcde6c2637da7e4115 |
File details
Details for the file opentelemetry_instrument_openai-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: opentelemetry_instrument_openai-0.3.0-py3-none-any.whl
- Upload date:
- Size: 9.7 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 | 313242c590fc0bddf462316f10193decee123b9f53d0f942e00dfcb0fe8298c4 |
|
MD5 | c43b9b2a6a13f709cb19a4e1d7000af9 |
|
BLAKE2b-256 | b958f69a1d1002ac316312b001b3f6b4ab92a2aa6512fe80607363c62fae1575 |