Skip to main content

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

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

Uploaded Source

Built Distribution

File details

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

File metadata

File hashes

Hashes for opentelemetry_instrument_openai-0.2.0.tar.gz
Algorithm Hash digest
SHA256 2b8d23dbc6113b4a2c7f2d5e5e5c59becae0d73b721863c1704180b026ce7963
MD5 4cf2109c976596b7e2ec6929a5b56721
BLAKE2b-256 22a7853f6b2afc22121d32df83af1fbb319f448e62252395cf558a1cace3bf92

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opentelemetry_instrument_openai-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0058487708d4d1c7cdf4cee8fbff9a8331a5243a85ff62b4769745a1835ae163
MD5 d0e1782034322a41fd36742ba593acb1
BLAKE2b-256 8e0f62d07966c4efc7450b5e35e968be265f8a3c2b0eaee590b9ce11f550a929

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