This guide will help you set up Langfuse observability for your Marketing Campaign Orchestrator.
Langfuse is an open-source LLM observability platform that helps you:
- Track agent reasoning: See how your agents think and make decisions
- Monitor LLM calls: View all prompts, completions, and token usage
- Analyze performance: Measure latency and identify bottlenecks
- Collect user feedback: Track approval/revision requests
- Debug issues: Replay entire conversation flows
- Python environment with the project requirements installed
- Google API key for the LLM
First, install the Langfuse packages (already added to requirements.txt):
pip install -r requirements.txt- Visit https://cloud.langfuse.com
- Sign up for a free account
- Create a new project (e.g., "Marketing Campaign Orchestrator")
- In your Langfuse project, navigate to Settings → API Keys
- Copy the following credentials:
- Public Key (starts with
pk-lf-...) - Secret Key (starts with
sk-lf-...)
- Public Key (starts with
Create a .env file in your project root (or update existing one):
# Google Gemini API Key (Required)
GOOGLE_API_KEY=your_gemini_api_key_here
# Langfuse Observability
LANGFUSE_PUBLIC_KEY=pk-lf-your_public_key_here
LANGFUSE_SECRET_KEY=sk-lf-your_secret_key_here
LANGFUSE_HOST=https://cloud.langfuse.comNote: The project will work WITHOUT Langfuse credentials, but tracing will be disabled.
streamlit run app.pyCheck the sidebar for:
- ✓ Langfuse Observability: Enabled (green) if configured correctly
- Langfuse Observability: Disabled (gray) if credentials are missing
python backend.pyThen make a test request:
curl -X POST "http://localhost:8000/run_campaign" \
-H "Content-Type: application/json" \
-d '{"goal": "Create a social media campaign for product launch"}'Check the response for langfuse_trace_url field.
- Run a campaign (via Streamlit or API)
- Go to https://cloud.langfuse.com
- Navigate to your project
- Click Traces in the sidebar
- You should see your campaign execution with:
- Trace: Overall workflow
- Generations: Individual LLM calls
- Scores: User feedback and validation results
Every agent node is tracked with:
- Input: Goal, current asset, retry count
- Output: Generated plans, drafts, critiques
- Metadata: Reasoning traces, iteration counts
All language model invocations include:
- Prompt: Full input prompt
- Completion: Model response
- Token Usage: Input/output token counts
- Latency: Response time
Retrieval and grading operations track:
- Query: Search query used
- Document Count: Number of documents retrieved
- Relevance Score: Whether retrieval was relevant
Content validations track:
- Status: Passed/failed
- Details: What was modified (if any)
- Asset Name: Which content was validated
Draft approvals and revisions track:
- Status: Approved, needs revision, pending
- Feedback Text: User's specific feedback
- Asset Name: Which draft was reviewed
Symptom: Warning message "Langfuse is not enabled"
Solutions:
- Verify
.envfile exists and contains the keys - Check key format (public key starts with
pk-lf-, secret withsk-lf-) - Restart the application after adding environment variables
Symptom: Application runs but no traces in Langfuse
Solutions:
- Check that you're logged into the correct project
- Verify API keys are from the same project you're viewing
- Wait a few seconds and refresh the dashboard
- Check application logs for Langfuse errors
Symptom: ModuleNotFoundError: No module named 'langfuse'
Solutions:
- Run
pip install langfuse langfuse-langchain - Verify you're in the correct Python environment
- Check
requirements.txtincludes the Langfuse packages
If you prefer to self-host Langfuse:
- Follow the Langfuse self-hosting guide
- Update your
.envfile with your self-hosted URL:LANGFUSE_HOST=https://your-langfuse-instance.com
- Explore Traces: Click on individual traces to see the full execution flow
- Analyze Patterns: Look for common failure modes or slow operations
- Set Up Alerts: Configure alerts for errors or latency spikes (Langfuse Pro)
- Export Data: Use Langfuse API to export data for custom analysis
- Langfuse Documentation: https://langfuse.com/docs
- Langfuse Discord: https://discord.gg/7NXusRtqYU
- Project Issues: Check your project's GitHub repository