Prerequisites
- Node.js 18+
- OpenAI API key
- Phoenix or another OpenTelemetry collector
Installation
Project Structure
Instrumentation Setup
Createinstrumentation.ts:
Express Server Setup
Createindex.ts:
Chat Controller with RAG
Createsrc/controllers/chat.controller.ts:
Vector Store Initialization
Createsrc/vector_store/store.ts:
Chat Route
Createsrc/routes/chat.route.ts:
Run the Server
Test with cURL
Key Features
Automatic Chain Tracing
LangChain instrumentation captures:- Retrieval chains: Document retrieval and ranking
- LLM calls: All language model interactions
- Prompt templates: Template rendering with variables
- Vector store queries: Similarity search operations
Manual Instrumentation
LangChain requires manual instrumentation due to its module structure:Production Considerations
- Use environment-based CORS configuration
- Implement proper error handling
- Add rate limiting and authentication
- Use persistent vector stores (Pinecone, Weaviate, etc.)
Next Steps
- Add streaming responses
- Implement agent patterns
- Explore Next.js integration