The Respan Tracing SDK for TypeScript/JavaScript provides comprehensive observability for your AI applications with automatic instrumentation for OpenAI, Anthropic, and other providers.
Automatically instrument OpenAI SDK calls. You must also install the OpenAI instrumentation package:
Copy
npm install @traceloop/instrumentation-openai
Copy
import OpenAI from 'openai';import { RespanTelemetry } from '@respan/tracing';const respanAi = new RespanTelemetry({ apiKey: process.env.RESPAN_API_KEY, appName: 'openai-example', instrumentModules: { openAI: OpenAI, // Automatically instrument OpenAI }});const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY});await respanAi.initialize();await respanAi.withWorkflow( { name: 'ai_chat' }, async () => { const completion = await openai.chat.completions.create({ model: 'gpt-3.5-turbo', messages: [ { role: 'system', content: 'You are a helpful assistant.' }, { role: 'user', content: 'Tell me a joke about programming.' } ], }); console.log(completion.choices[0].message.content); });await respanAi.shutdown();
Next.js users: Do not initialize @respan/tracing inside Next.js’s instrumentation.ts file. This runs too early in the application lifecycle and interferes with OpenAI instrumentation timing, resulting in broken or missing traces. Instead, create a separate initialization file (e.g., src/lib/respan-init.ts) and import it where needed.