Skip to main content

Langfuse Integration

Langfuse is an open-source LLM engineering platform for tracing, evaluation, and monitoring.

Setup

1. Install Dependencies

pip install opentelemetry-sdk opentelemetry-exporter-otlp

2. Set Environment Variables

export LANGFUSE_PUBLIC_KEY=pk-lf-xxx
export LANGFUSE_SECRET_KEY=sk-lf-xxx
# Optional: for self-hosted
export LANGFUSE_HOST=https://cloud.langfuse.com

3. Initialize

from praisonai_tools.observability import obs

obs.init(provider="langfuse")

Usage

Basic Tracing

from praisonai_tools.observability import obs
from praisonaiagents import Agent

obs.init(provider="langfuse")

agent = Agent(
    instructions="You are a helpful assistant.",
    model="gpt-4o-mini",
)

with obs.trace("chat-session", session_id="user-123"):
    response = agent.chat("What is the capital of France?")
    print(response)

With Spans

from praisonai_tools.observability import obs
from praisonai_tools.observability.base import SpanKind

obs.init(provider="langfuse")

with obs.trace("workflow"):
    with obs.span("research", kind=SpanKind.AGENT):
        # Research phase
        pass
    
    with obs.span("writing", kind=SpanKind.AGENT):
        # Writing phase
        pass

Configuration Options

OptionEnvironment VariableDescription
public_keyLANGFUSE_PUBLIC_KEYYour Langfuse public key
secret_keyLANGFUSE_SECRET_KEYYour Langfuse secret key
hostLANGFUSE_HOSTLangfuse host URL (default: cloud.langfuse.com)

View Traces

Visit cloud.langfuse.com to view your traces and analytics.