Skip to main content

OpenTelemetry openai instrumentation

Project description

opentelemetry-instrument-openai

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

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.1.0.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

File details

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

File metadata

File hashes

Hashes for opentelemetry_instrument_openai-0.1.0.tar.gz
Algorithm Hash digest
SHA256 9c68a3b7a0f0ece6fee0aab18baecb6151ca4c05f4d6a9eaff72ba1f81546ac3
MD5 0e36f5d820e23debd6a9e79a15d016b3
BLAKE2b-256 2eb638849d4f7ac681cc20f5476dd6d5c317afdfd0d403b6b1d0da48fd0702f6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for opentelemetry_instrument_openai-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 175c751eec17d542d26e3948a9394a5b7bd91ad8fd2a5f2d9d6e4b06e2abc920
MD5 989c89412d7bee3685f6910cd4089c73
BLAKE2b-256 04cece27f0d7412b5fc35297178aa91a6ffc5785d84152dc0fa5e19fbf407160

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