Prerequisites
- Node.js 18+
- OpenAI API key
- Phoenix or another OpenTelemetry collector running
Installation
1
Install dependencies
2
Set environment variables
Instrumentation Setup
Create aninstrumentation.ts file:
Complete Example
Create achat.ts file:
Streaming Example
Function Calling Example
Key Features
Automatic Instrumentation
The OpenAI instrumentation automatically traces:- Chat completions: Standard and streaming responses
- Embeddings: Text embedding generation
- Function calling: Tool use and execution
- Vision: Image inputs with multimodal models
Manual Instrumentation Check
UseisPatched() to verify instrumentation is active:
Resource Attributes
Add project metadata:Next Steps
- Learn about Next.js integration
- Explore LangChain with Express
- See trace configuration