Langfuse Integration
Langfuse is an open-source LLM observability platform that provides tracing, analytics, and evaluation capabilities for AI applications.
Overview
The Langfuse integration enables LangGuard to:
- Import traces from your Langfuse projects
- Sync metrics including token usage and costs
- Track sessions and user interactions
- Apply policies to Langfuse traces
Prerequisites
- A Langfuse account (cloud or self-hosted)
- A Langfuse project with traces
- API credentials (Public Key and Secret Key)
Getting Your API Keys
- Log in to Langfuse Cloud
- Select your project
- Navigate to Settings > API Keys
- Copy the Public Key (starts with
pk-lf-) - Copy the Secret Key (starts with
sk-lf-)
Click "Create New API Key" if you need a dedicated key for LangGuard. This makes rotation easier.
Setup
Step 1: Add Integration
- Navigate to Settings > Integrations in LangGuard
- Click Add Integration
- Select Langfuse
Step 2: Configure Credentials
Enter your credentials:
| Field | Description | Required |
|---|---|---|
| Name | Friendly name (e.g., "Production Langfuse") | Yes |
| Public Key | Your Langfuse public key | Yes |
| Secret Key | Your Langfuse secret key | Yes |
| Host URL | API host URL | No (defaults to cloud) |
Host URL Examples:
- Langfuse Cloud:
https://cloud.langfuse.com(default) - Self-hosted:
https://langfuse.your-company.com - Local:
http://localhost:3001
Step 3: Test Connection
- Click Test Connection
- Verify you see "Connection successful"
- If failed, check credentials and host URL
Step 4: Configure Sync
Set up synchronization preferences:
| Setting | Recommended | Description |
|---|---|---|
| Auto Sync | Enabled | Automatic background sync |
| Interval | 5 minutes | Time between syncs |
| Lookback | 7 days | How far back to sync |
| Batch Size | 100 | Traces per sync operation |
Step 5: Save
Click Save to complete setup.
Configuration Options
Environment Variables
You can also configure Langfuse via environment variables:
# Primary Langfuse credentials
LANGFUSE_PUBLIC_KEY=pk-lf-your-public-key
LANGFUSE_SECRET_KEY=sk-lf-your-secret-key
LANGFUSE_HOST=https://cloud.langfuse.com
UI-configured credentials take precedence over environment variables.
Multiple Projects
To connect multiple Langfuse projects:
- Add separate integrations for each project
- Give each a descriptive name (e.g., "Langfuse - Production", "Langfuse - Staging")
- Use different API keys for each
What Gets Synced
Traces
Each Langfuse trace becomes a LangGuard trace:
| Langfuse Field | LangGuard Field |
|---|---|
id | externalId |
name | name |
timestamp | timestamp |
latency | duration |
input | input |
output | output |
metadata | metadata |
userId | userId |
sessionId | sessionId |
tags | tags |
Spans
Trace spans are preserved:
- Generations (LLM calls)
- Retrievals (RAG operations)
- Custom spans
Observations
Langfuse observations map to LangGuard metadata:
- Token counts
- Cost estimates
- Model information
- Latency breakdown
Agent Detection
LangGuard automatically detects agents from Langfuse traces using:
- Trace tags - Tags like
agent:CustomerService - Metadata fields -
agent_name,agentName, etc. - Naming patterns - Consistent trace naming
Best Practices for Agent Detection
Include agent information in your Langfuse instrumentation:
# Python SDK example
from langfuse import Langfuse
langfuse = Langfuse()
trace = langfuse.trace(
name="customer_query",
tags=["agent:CustomerService"],
metadata={
"agent_name": "CustomerService",
"agent_version": "2.1.0"
}
)
Sync Behavior
Incremental Sync
By default, syncs are incremental:
- LangGuard tracks the last sync timestamp
- Each sync fetches traces since that time
- Duplicate traces are skipped
Backfill
For initial setup or catching up:
- Click Sync Now with "Backfill" option
- Or set a longer lookback period
- Historical traces are imported
Conflict Resolution
When the same trace is synced multiple times:
- Later syncs update existing traces
- Metadata is merged (not replaced)
- Violations are re-evaluated
Troubleshooting
Connection Failed
Error: Authentication failed: Invalid API credentials
Solutions:
- Verify Public Key starts with
pk-lf- - Verify Secret Key starts with
sk-lf- - Check keys are for the correct project
- Ensure keys haven't been revoked
No Traces Synced
Possible causes:
- Time range - Check lookback period includes when traces were created
- Empty project - Verify traces exist in Langfuse
- Filtering - Check if any filters are excluding traces
Rate Limiting
Error: Rate limit exceeded
Solutions:
- Increase sync interval (e.g., 10 minutes instead of 5)
- Reduce batch size
- Contact Langfuse support for higher limits
Self-Hosted Issues
For self-hosted Langfuse:
- Ensure Host URL is correct (include protocol, no trailing slash)
- Verify network connectivity from LangGuard to Langfuse
- Check TLS certificate validity
- Review Langfuse server logs
API Reference
Sync Endpoint
Manually trigger sync:
POST /api/integrations/{id}/sync
Content-Type: application/json
{
"mode": "incremental",
"limit": 100
}
Status Endpoint
Check integration status:
GET /api/integrations/{id}/sync/status
Response:
{
"success": true,
"data": {
"isActive": false,
"hasSchedule": true,
"lastSync": {
"id": "sync_123",
"status": "completed",
"itemsFetched": 45,
"itemsIngested": 45,
"completedAt": "2024-03-15T10:30:00Z"
}
}
}
Next Steps
- Quick Start Guide - See your Langfuse traces in action
- Policies - Apply governance rules to traces
- Agent Activity - Visualize agent behavior