openai SDK ships no first-party OTel: use OpenInference’s auto-instrumentation. Pick your language in the code blocks below; the choice persists across the page.
OpenInference can capture full OpenAI prompts, completions, tool calls, and token metadata. Review Data Governance before enabling production traffic.
1. Install
Already have OpenInference + an OTLP exporter wired up? Skip. No setup yet?2. Wire OpenInference + OTLP exporter pointing at Agnost
Already have OpenInference (or any OTel TracerProvider) running? Append Agnost as an additional span processor on the existing provider:3. Pass userId / sessionId per call
using_attributes (Python) and setUser / setSession (TS) propagate via OTel context, landing as user.id / session.id on every span the OpenAI SDK emits inside the block.
What appears in Agnost
- Conversations grouped by
session.id. - User-level analytics grouped by
user.id. - Raw logs containing OpenInference spans.
- Tool calls when OpenAI tool-use spans are emitted.
Verify
Run one OpenAI call inside the context block, then open Raw logs in Agnost. Confirmuser.id, session.id, model, and message attributes are present.
Troubleshooting
- Import and initialize instrumentation before creating the OpenAI client.
- Confirm the OTLP exporter points at
https://otel.agnost.ai/v1/traces. - For TypeScript, confirm the
openaiand@arizeai/openinference-instrumentation-openaiversions match the table below.
TypeScript version compatibility
Pin matching majors: version mismatches throwdoes not provide an export named 'APIPromise' at import time:
