Install
Instrument
What gets captured
Every call to the following becomes anllm span:
client.chat.completions.create(including streaming)client.completions.createclient.embeddings.createclient.responses.create(if available in your SDK version)
input— the fullmessagesarray (orprompt)output— the response contentmodelprompt_tokens,completion_tokenslatency_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 thechoices[].message.tool_calls field. If you want each tool execution to be its own span, wrap your tool invocation:
Disabling temporarily
Known gotchas
clientreuse across threads/tasks — instrumentation patches the instance, not the class; spawning a newOpenAI()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
AzureOpenAIand the sameinstrument_openai()call; fields are identical.