TracingGuidesInstrumentationFrameworks

OpenAI

chat.completions, responses, and embeddings auto-capture as kind='llm' spans, including streaming.

Install the instrumentor next to the openai SDK and every call inside a wrapped run becomes a span with model, tokens, temperature, prompt, and completion. The provider field is openai.

What's captured

CallSpan kindAuto-extracted
client.chat.completions.createllmmodel, input/output tokens, temperature, messages, completion
client.responses.createllmmodel, tokens, input, output text
client.embeddings.createllmmodel, input tokens, input text
Streaming (stream: true)llmeverything above, tokens from the final chunk.usage

Azure OpenAI and OpenAI-compatible endpoints (Together, Groq) fire the same instrumentation and report provider='openai'.

When Node calls aren't captured

In Node, the OpenAI instrumentor hooks openai 4.19 to 6.x under CommonJS. It does not hook openai v7 (what npm install openai gives you today), and it does not hook any version under ES modules. Calls still work; they just record no span, and the SDK says so at startup.

Wrap the call instead. This works on every version and module system:

const chat = trodo.llm(
  'openai.chat',
  (messages) => client.chat.completions.create({ model: 'gpt-4o-mini', messages }),
  { model: 'gpt-4o-mini', provider: 'openai' },
);

const res = await chat(messages);

Or pin openai to ^6 and run under CommonJS. Python is not affected.

Install

npm install openai @opentelemetry/instrumentation-openai
pip install openai opentelemetry-instrumentation-openai

Minimal example

import trodo from 'trodo-node';
import OpenAI from 'openai';

trodo.init({ siteId: process.env.TRODO_SITE_ID! });
const openai = new OpenAI();

await trodo.wrapAgent('faq-bot', async (run) => {
  const r = await openai.chat.completions.create({
    model: 'gpt-4o-mini',
    messages: [{ role: 'user', content: 'What is HNSW?' }],
  });
  run.setOutput(r.choices[0].message.content); // one kind='llm' span, no extra code
});
import os, trodo
from openai import OpenAI

trodo.init(site_id=os.environ['TRODO_SITE_ID'])
client = OpenAI()

with trodo.wrap_agent('faq-bot') as run:
    r = client.chat.completions.create(
        model='gpt-4o-mini',
        messages=[{'role': 'user', 'content': 'What is HNSW?'}],
    )
    run.set_output(r.choices[0].message.content)

On this page