await trodo.withSpan({ kind: 'llm', name: 'chat.completions' }, async (span) => {
// AUTO-populated when using OpenAI / Anthropic / Bedrock / Cohere / Gemini /
// Vertex / Mistral / LangChain / LlamaIndex / Vercel AI SDK.
// Set these manually only when calling the provider via raw fetch.
span.setLlm({
model: 'gpt-4o-mini', // auto
provider: 'openai', // auto
inputTokens: 120, // auto (from response.usage)
outputTokens: 64, // auto
cost: 0.00034, // auto (computed from tokens + model)
temperature: 0.2, // auto (from request body)
});
// Always manual:
span.setInput({ prompt: '...' });
span.setOutput({ completion: '...' });
span.setAttribute('customer_tier', 'enterprise');
try {
return await openai.chat.completions.create({ ... });
} catch (err) {
span.setError({ type: 'RateLimitError', message: err.message }); // status = 'error'
throw err;
}
});
// Tool span — toolName is required:
await trodo.withSpan({ kind: 'tool', name: 'search_kb', toolName: 'search_kb' }, async (span) => {
span.setInput({ query });
const results = await kb.search(query);
span.setOutput({ count: results.length });
return results;
});