This repository demonstrates how to integrate Langfuse observability with both Node.js and Bun applications using OpenTelemetry. It showcases tracing, AI integration, and modern TypeScript development practices.
Both examples use OpenTelemetry for comprehensive tracing:
apps/bun-example/src/tracing.ts- Bun tracing setupapps/node-example/src/tracing.ts- Node.js tracing setup
Demonstrates AI SDK usage with proper observability:
apps/bun-example/src/ai-example.ts- Bun AI exampleapps/node-example/src/ai-example.ts- Node.js AI example
Features:
- Text generation with Google's Generative AI
- Automatic tracing of AI calls with Langfuse
- Support for custom tags and metadata
- Token usage tracking
Both applications expose the following endpoints:
GET /- Welcome messageGET /test- Custom tracing demonstration with simulated DB and API operationsGET /ai-test?prompt=<text>- AI text generation with Langfuse tracing
- Node.js 18+ or Bun 1.0+
- PNPM package manager
- Langfuse account (for API keys)
- Google AI API key (for AI examples)
- Clone the repository:
git clone https://github.com/yourusername/langfuse-test-node-bun.git
cd langfuse-test-node-bun- Install dependencies:
pnpm install- Set up environment variables in each app directory:
# For both apps/bun-example and apps/node-example
cp .env.example .env- Configure your
.envfile with:
LANGFUSE_PUBLIC_KEY=your_langfuse_public_key
LANGFUSE_SECRET_KEY=your_langfuse_secret_key
LANGFUSE_BASEURL=https://cloud.langfuse.com
GOOGLE_GENERATIVE_AI_API_KEY=your_google_ai_keypnpm bun:devThis starts the Bun server with hot reload on http://localhost:3001
pnpm node:devThis starts the Node.js server with watch mode
Once running, all traces are automatically sent to Langfuse where you can:
- View request traces with timing information
- Analyze AI model usage and performance
- Debug issues with detailed span data
- Monitor application health
Access your traces at: https://cloud.langfuse.com
curl http://localhost:3001/testThis endpoint demonstrates custom OpenTelemetry spans with simulated database operations, external API calls, and data processing.
curl "http://localhost:3001/ai-test?prompt=Write%20a%20haiku%20about%20observability"This endpoint uses the Google Generative AI model with full Langfuse tracing integration.
- @opentelemetry/* - Distributed tracing
- @langfuse/langfuse - Observability platform
- @ai-sdk/google - AI SDK for Google's models
- hono - Web framework
- zod - Schema validation