Skip to main content

Install

Instrument

What gets captured

Every call to the following becomes an llm span:
  • client.chat.completions.create (including streaming)
  • client.completions.create
  • client.embeddings.create
  • client.responses.create (if available in your SDK version)
Captured on each span:
  • input — the full messages array (or prompt)
  • output — the response content
  • model
  • prompt_tokens, completion_tokens
  • latency_ms
  • Any errors (with type and message)

Streaming

Streaming responses are fully supported — the span is held open until the stream closes, at which point the concatenated output and final token counts are recorded.

Tool calling

Tool calls are captured in the span’s output as part of the choices[].message.tool_calls field. If you want each tool execution to be its own span, wrap your tool invocation:

Disabling temporarily

Known gotchas

  • client reuse across threads/tasks — instrumentation patches the instance, not the class; spawning a new OpenAI() gives you an uninstrumented client. Instrument each one, or construct and instrument a single shared client.
  • Custom base_url — works fine; the span records whatever model you request.
  • Azure OpenAI — use AzureOpenAI and the same instrument_openai() call; fields are identical.