Skip to main content
The 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:
No OTel yet? Full setup:

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. Confirm user.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 openai and @arizeai/openinference-instrumentation-openai versions match the table below.

TypeScript version compatibility

Pin matching majors: version mismatches throw does not provide an export named 'APIPromise' at import time:

References