OpenAI OpenTelemetry Integration
Overview
This integration provides support for using OpenTelemetry with the OpenAI framework. It enables tracing and monitoring of applications built with OpenAI.
Installation
- Install traceAI OpenAI
pip install traceAI-openai
Set environment variables
Set the Future AGI keys for tracing and the OpenAI key for the Quickstart request:
export FI_API_KEY="your-future-agi-api-key"
export FI_SECRET_KEY="your-future-agi-secret-key"
export OPENAI_API_KEY="your-openai-api-key"
Ollama and self-hosted OpenAI-compatible clients
Keep using this package when your application calls Ollama through the OpenAI
SDK. The official https://ollama.com/v1 endpoint is attributed to ollama
automatically. A local address can host many providers, so set the provider
explicitly for each local or self-hosted client:
from openai import OpenAI
from traceai_openai import OpenAIInstrumentor, set_client_provider
# Use the trace provider configured in the quickstart below.
OpenAIInstrumentor().instrument(tracer_provider=trace_provider)
client = OpenAI(base_url="http://localhost:11434/v1", api_key="ollama")
set_client_provider(client, provider="ollama")
The override controls gen_ai.provider.name on sync and async requests,
including streams, embeddings, Responses and failures. It changes tracing
metadata only; it adds no spans and sends no provider setting to the server.
Use a lowercase provider identifier (1–64 characters, starting with a letter;
letters, digits, ., _ and - are accepted), not a URL or secret.
Set the override before making requests. It takes precedence over host detection;
set_client_provider(client, provider=None) restores host detection. Other
clients are unaffected. A client returned by copy() or with_options() is a
separate instance: set its override explicitly too, especially if its endpoint
changes. Unconfigured loopback, proxy and unknown hosts retain the historical
openai label; the instrumentor never assumes a local server is Ollama.
For applications using the native ollama Python client instead, use
traceai-ollama. Do not install both instrumentors for the same API call.
See Ollama's OpenAI compatibility guide
for supported endpoints and models.
Quickstart
Register Tracer Provider
Set up the trace provider to establish the observability pipeline. The trace provider:
from fi_instrumentation import register
from fi_instrumentation.fi_types import ProjectType
trace_provider = register(
project_type=ProjectType.OBSERVE,
project_name="openai_app"
)
Configure OpenAI Instrumentation
Set up your OpenAI client with built-in observability. This includes support for text, image, and audio models.
from traceai_openai import OpenAIInstrumentor
OpenAIInstrumentor().instrument(tracer_provider=trace_provider)
Make a traced request
Create the client after calling OpenAIInstrumentor().instrument(...).
from openai import OpenAI
# OpenAI reads OPENAI_API_KEY from your environment.
with OpenAI() as client:
response = client.chat.completions.create(
model="gpt-4o-mini",
messages=[
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Can you tell me a joke?"},
],
)
print((response.choices[0].message.content or "").strip())
trace_provider.force_flush() # Flush before a short-lived script exits.
Vercel AI Gateway
Use the same OpenAIInstrumentor for Chat Completions sent to Vercel AI Gateway;
no gateway-specific package or OpenAI key is needed. Set AI_GATEWAY_API_KEY to your Vercel
AI Gateway key and AI_GATEWAY_MODEL to a current
model ID:
export AI_GATEWAY_API_KEY="your-vercel-ai-gateway-key"
export AI_GATEWAY_MODEL="<provider>/<model>"
Keep the tracer registration and instrumentation from the Quickstart above, then replace its OpenAI client and request with:
import os
from openai import OpenAI
client = OpenAI(
base_url="https://ai-gateway.vercel.sh/v1",
api_key=os.environ["AI_GATEWAY_API_KEY"],
)
response = client.chat.completions.create(
model=os.environ["AI_GATEWAY_MODEL"],
messages=[{"role": "user", "content": "Say hello in five words."}],
)
print(response.choices[0].message.content)
trace_provider.force_flush() # Flush before a short-lived script exits.
The documented gateway host is labelled gen_ai.provider.name="vercel".
This identifies the service the client calls, not the upstream model provider
or a fallback provider. Unknown proxies and look-alike hosts retain their existing
provider label. Sync, async, streamed and failed calls use the same attribution.
Client spans capture prompts, responses and returned token usage. They do not
reconstruct gateway routing, retries, cost or provider attempts. Vercel's separate
Trace Drains
provide those gateway details but omit prompts and completions. A drain is not
configured by OpenAIInstrumentor; do not sum client and drain token counts for
the same request as separate model usage.
Metadata
Release files for traceAI-openai 0.1.13
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| traceai_openai-0.1.13.tar.gz | 36.0 kB | With provenance | Details for traceai_openai-0.1.13.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| traceai_openai-0.1.13-py3-none-any.whl | Python 3 | none | any | Details for traceai_openai-0.1.13-py3-none-any.whl |
Total release size: 78.4 kB
Release files / traceai_openai-0.1.13.tar.gz
| Download URL | traceai_openai-0.1.13.tar.gz |
|---|---|
| Size | 36.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
67bd0d0bb5ee70aecfad8aae72f251888f35044ed0677c6eed04a18600be31a1
|
|
BLAKE2b-256 checksum How to use checksums |
f0a89efa709149fe9f30a758d856ecf71889892076c496e34db022ed131f0e06
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.
Transparency logRelease files / traceai_openai-0.1.13-py3-none-any.whl
| Download URL | traceai_openai-0.1.13-py3-none-any.whl |
|---|---|
| Size | 42.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
52b3185b3d8c54fee41555f46b445f828b84612acc6af9fe80b29dfdb14e65b7
|
|
BLAKE2b-256 checksum How to use checksums |
4a6130e19e26bcbed473ddd358a0ebbddc398cef16006a37200bdd663bfc4305
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.
Transparency logSecurity for traceAI-openai 0.1.13
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for traceai_openai-0.1.13.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 5, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.