Skip to main content

pypi

This library allows tracing LLM requests and logging of messages made by the OpenAI Python API library. It also captures the duration of the operations and the number of tokens used as metrics.

Many LLM platforms support the OpenAI SDK. This means systems such as the following are observable with this instrumentation when accessed using it:

OpenAI Compatible Platforms

Name

gen_ai.system

Azure OpenAI

az.ai.openai

Gemini

gemini

Perplexity

perplexity

xAI (Compatible with Anthropic)

xai

DeepSeek

deepseek

Groq

groq

MistralAI

mistral_ai

Installation

If your application is already instrumented with OpenTelemetry, add this package to your requirements.

pip install splunk-otel-instrumentation-openai

If you don’t have an OpenAI application, yet, try our examples which only need a valid OpenAI API key.

Check out zero-code example for a quick start.

Usage

This section describes how to set up OpenAI instrumentation if you’re setting OpenTelemetry up manually. Check out the manual example for more details.

Instrumenting all clients

When using the instrumentor, all clients will automatically trace OpenAI operations including chat completions and embeddings. You can also optionally capture prompts and completions as log events.

Make sure to configure OpenTelemetry tracing, logging, and events to capture all telemetry emitted by the instrumentation.

from opentelemetry.instrumentation.openai_v2 import OpenAIInstrumentor

OpenAIInstrumentor().instrument()

client = OpenAI()
# Chat completion example
response = client.chat.completions.create(
    model="gpt-4o-mini",
    messages=[
        {"role": "user", "content": "Write a short poem on open telemetry."},
    ],
)

# Embeddings example
embedding_response = client.embeddings.create(
    model="text-embedding-3-small",
    input="Generate vector embeddings for this text"
)

Enabling message content

Message content such as the contents of the prompt, completion, function arguments and return values are not captured by default. To capture message content as log events, set the environment variable OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT to true.

See the upstream OpenTelemetry documentation for more details.

Suppressing nested instrumentation

When using multiple instrumentations together (e.g., LangChain + OpenAI), the higher-level instrumentation automatically sets SUPPRESS_LANGUAGE_MODEL_INSTRUMENTATION_KEY in the OpenTelemetry context to prevent duplicate spans for the same underlying LLM call.

This is handled transparently — no user configuration is needed. For example, when LangChain instrumentation is active alongside OpenAI instrumentation, you will see LangChain spans without redundant nested OpenAI spans.

Uninstrument

To uninstrument clients, call the uninstrument method:

from opentelemetry.instrumentation.openai_v2 import OpenAIInstrumentor

OpenAIInstrumentor().instrument()
# ...

# Uninstrument all clients
OpenAIInstrumentor().uninstrument()

References

Metadata

Release files for splunk-otel-instrumentation-openai 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for splunk-otel-instrumentation-openai 0.1.2
File Size Uploaded
splunk_otel_instrumentation_openai-0.1.2.tar.gz 189.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for splunk-otel-instrumentation-openai 0.1.2
File Interpreter ABI Platform
splunk_otel_instrumentation_openai-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 209.2 kB

Release files / splunk_otel_instrumentation_openai-0.1.2.tar.gz

Download URL splunk_otel_instrumentation_openai-0.1.2.tar.gz
Size 189.7 kB
Tags Source
SHA-256 checksum
How to use checksums
df7bde6dbae5eb929452d3ce2655e528eaedb29f6585478b4e3bc3f7a12a157d
BLAKE2b-256 checksum
How to use checksums
17a453afdf5815f9286a8b06826811fc6d3910d95c6aa1a51948b3d5a51f986b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Hatch/1.16.5 cpython/3.11.15 HTTPX/0.28.1

Release files / splunk_otel_instrumentation_openai-0.1.2-py3-none-any.whl

Download URL splunk_otel_instrumentation_openai-0.1.2-py3-none-any.whl
Size 19.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b36c2022c43ab37bdcb467715a002638f1bfaad24de114f89c45b3cdc1cfecb7
BLAKE2b-256 checksum
How to use checksums
053c2793307c9e0241ca9ad22bbc9ec6be0f3ddbef3444c04d4391bb65054431
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via Hatch/1.16.5 cpython/3.11.15 HTTPX/0.28.1

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page