Spaces:
Sleeping
Sleeping
Langfuse Monitoring Setup
This guide helps you set up Langfuse monitoring for your LangGraph application to track LLM responses, costs, and performance.
π Quick Start
1. Start Langfuse Services
# Start Langfuse database and server
docker-compose up -d langfuse-db langfuse-server
# Or use the setup script
python setup_langfuse.py
2. Configure Langfuse
- Open http://localhost:3000 in your browser
- Create an account or sign in
- Create a new project (or use the default one)
- Go to Settings β API Keys
- Copy the Secret Key and Public Key
3. Update Environment Variables
Add to your .env file:
LANGFUSE_SECRET_KEY=sk-lf-your-secret-key-here
LANGFUSE_PUBLIC_KEY=pk-lf-your-public-key-here
LANGFUSE_HOST=http://localhost:3000
4. Start the Application
# Start all services including your app
docker-compose up --build
# Or start just your app if Langfuse is already running
docker-compose up langgraph-agenticai
π What Gets Monitored
- LLM Requests & Responses: All interactions with Groq models
- Token Usage: Input and output tokens for cost calculation
- Response Times: Latency metrics for performance monitoring
- User Sessions: Track user interactions across conversations
- Tool Usage: Monitor MCP and other tool executions
- Error Tracking: Capture and analyze failures
π― Features
In-App Monitoring
- β Real-time monitoring status in sidebar
- β Direct link to Langfuse dashboard
- β Session tracking across conversations
- β Automatic cost tracking
Langfuse Dashboard
- π Traces: Detailed view of each conversation
- π° Costs: Token usage and cost breakdown
- β‘ Performance: Response time analytics
- π Search: Find specific interactions
- π Analytics: Usage patterns and trends
π§ Configuration Options
Environment Variables
| Variable | Description | Default |
|---|---|---|
LANGFUSE_SECRET_KEY |
Your Langfuse secret key | Required |
LANGFUSE_PUBLIC_KEY |
Your Langfuse public key | Required |
LANGFUSE_HOST |
Langfuse server URL | http://localhost:3000 |
TELEMETRY_ENABLED |
Enable Langfuse telemetry | true |
Docker Compose Services
- langfuse-db: PostgreSQL database for Langfuse
- langfuse-server: Langfuse web application
- langgraph-agenticai: Your main application
π οΈ Troubleshooting
Langfuse Not Starting
# Check service logs
docker-compose logs langfuse-server
docker-compose logs langfuse-db
# Restart services
docker-compose restart langfuse-server langfuse-db
Connection Issues
- Verify environment variables are set correctly
- Check that Langfuse is accessible at http://localhost:3000
- Ensure API keys are valid and have proper permissions
Monitoring Not Working
- Check the sidebar for monitoring status
- Verify Langfuse credentials in
.envfile - Look for error messages in the Streamlit app
π Advanced Usage
Custom Traces
from src.langgraphagenticai.monitoring.langfuse_integration import langfuse_manager
# Create custom trace
trace = langfuse_manager.create_trace(
name="custom_operation",
user_id="user123",
session_id="session456"
)
Cost Analysis
Access detailed cost breakdowns in the Langfuse dashboard:
- Go to Analytics β Usage
- Filter by model, user, or time period
- Export data for further analysis
π Useful Links
π Support
If you encounter issues:
- Check the troubleshooting section above
- Review Docker Compose logs
- Consult Langfuse documentation
- Open an issue in the project repository