Capabilities Overview
LLM Generation Tracking
Record input messages, output content, model parameters, and token usage.
Tool Call Observation
Track tool parameters, execution results, duration, and call hierarchy.
Nested Trace Support
Observe multi-layer call chains and follow-up generations.
Streaming Compatibility
Works with both streaming and non-streaming model responses.
Installation and Configuration
Install Langfuse dependencies
Langfuse is already included in the project dependencies. In an existing environment, you can also install it directly:
- Poetry
- pip
Get project credentials
- Visit Langfuse
- Create a project
- Copy the public key and secret key
The current implementation does not automatically skip observability calls based on
LANGFUSE_ENABLED. If you need environment-based enable/disable behavior, gate that logic explicitly at the application layer.Configuration Methods
- Shell environment variables
- Set values in Python before import
Usage Examples
Basic LLM function tracing
Basic LLM function tracing
Tracing a tool-augmented workflow
Tracing a tool-augmented workflow
Tracing a chat workflow
Tracing a chat workflow
Trace Structure
Generation traces
Generation traces
Each LLM call creates a generation trace that typically includes:
- input messages
- output content and any tool calls
- model name and parameters
- token usage and cost data
- streaming mode and related metadata
Tool traces
Tool traces
Each tool invocation records:
- call parameters
- execution result
- tool call ID, duration, and related metadata
Hierarchy example
Hierarchy example
Configuration Options
Environment variables
| Variable | Description | Default | Required |
|---|---|---|---|
LANGFUSE_PUBLIC_KEY | Langfuse public key | - | Yes |
LANGFUSE_SECRET_KEY | Langfuse secret key | - | Yes |
LANGFUSE_BASE_URL | Langfuse server URL | https://cloud.langfuse.com | No |
LANGFUSE_EXPORT_ALL_SPANS | Export all OpenTelemetry spans | true | No |
LANGFUSE_ENABLED | Enable observability | true | No |
Langfuse v4 notes
- Langfuse v4 filters non-LLM OpenTelemetry spans by default; the framework keeps the older “export all spans” behavior unless you disable it explicitly.
- Langfuse v4 also normalizes metadata values to strings and limits their length. The framework already stringifies metadata to match that behavior.
Best Practices
Environment separation
Environment separation
Error handling and logs
Error handling and logs
Monitor application logs and Langfuse connectivity, especially in high-volume or long-running workflows.
Privacy and performance
Privacy and performance
- Review what data is sent to Langfuse
- Avoid uploading sensitive content without a clear policy
- Tune provider timeouts and observability overhead for production
Troubleshooting
Observability is not active
Observability is not active
Check whether the required environment variables are set and whether the Langfuse package is installed.
Connection failed
Connection failed
Verify network access, credentials, and
LANGFUSE_BASE_URL.No data appears in Langfuse
No data appears in Langfuse
Confirm you are looking at the correct project and allow a short delay for ingestion.