Skip to main content

OpenTelemetry openai instrumentation

Project description

opentelemetry-instrument-openai

It's OpenTelemetry instrumentation (python) for OpenAI's library.

Project site: https://github.com/cartermp/opentelemetry-instrument-openai-py

How to use it

Simple! First, install this package.

Usage

With autoinstrumentation agent:

poetry add opentelemetry-instrument-openai
poetry run opentelemetry-bootstrap -a install
poetry run opentelemetry-instrument python your_app.py

If you prefer to do it in code, you can do that 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.

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

opentelemetry_instrument_openai-0.4.0.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file opentelemetry_instrument_openai-0.4.0.tar.gz.

File metadata

File hashes

Hashes for opentelemetry_instrument_openai-0.4.0.tar.gz
Algorithm Hash digest
SHA256 7dd9b251cd84c04e1fa770c0dd602026ce170ccc597402f49275f892d4c5b649
MD5 f905884c5aaad3b7a9175be84bfc52e5
BLAKE2b-256 096502abff5ad2870e3925b2e14c08485d723103fd15e03eff72f1303294a7e7

See more details on using hashes here.

File details

Details for the file opentelemetry_instrument_openai-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for opentelemetry_instrument_openai-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c6beb0020702fc5a183773c94fdc983597d42602e3dee4e274f2759e20a67f59
MD5 baae9e4673c9eb48ab6ec61446f40248
BLAKE2b-256 51bdf8c67586ea7cfef1041436591341ede75a27eebef87801baf1b380cd153c

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page