Skip to main content
Langfuse provides observability and evaluation tools for LLM applications with automatic tracing of all agent conversations.

Path Comparison

Path A — obs.langfuse()Path B — praisonai --observe langfuse
UsagePython scriptCLI flag (also PRAISONAI_OBSERVE=langfuse)
MechanismInstruments OpenAI client globally via langfuse.openai drop-inLangfuseSink + ContextTraceEmitter bridge
Span CoveragePer-LLM-call generations (input/output, tokens, model)Full lifecycle: agent_start, agent_end, tool_call_*, llm_*
Manual flush needed?Yes — provider.flush()No — atexit registers it
Best forProgrammatic agents, any Python flowYAML / CLI workflows, multi-agent pipelines

Quick Start

1

Install and Enable

2

Auto-Detection


How Path A Works — obs.langfuse()

ComponentPurpose
obs.langfuse()Instruments OpenAI client globally for automatic tracing
AgentMakes LLM calls that are automatically traced
Langfuse SDKCaptures traces via langfuse.openai drop-in

Environment Variables

VariableRequiredDescription
LANGFUSE_PUBLIC_KEYYour Langfuse public key (pk-lf-...)
LANGFUSE_SECRET_KEYYour Langfuse secret key (sk-lf-...)
LANGFUSE_BASE_URLFor self-hostedBase URL e.g. http://localhost:3000
LANGFUSE_HOSTFor compatibilitySame as LANGFUSE_BASE_URL
As of PraisonAI’s wrapper-layer refactor, OTEL_SDK_DISABLED and EC_TELEMETRY are only set on first observability use, not at import. User-set values are preserved (setdefault). If LANGFUSE_PUBLIC_KEY is set or ~/.praisonai/langfuse.env exists, OTEL_SDK_DISABLED=false is set explicitly so Langfuse v4 can use OTel internally.

CLI Observability — --observe langfuse

Enable full agent lifecycle tracing with a single CLI flag:

What Gets Traced

The CLI --observe langfuse captures:
  • Agent lifecycle: agent_start / agent_end spans
  • LLM interactions: llm_request / llm_response with readable content
  • Tool usage: tool_call_start / tool_call_end with args and results
  • Automatic flush: No manual provider.flush() required
As of PR #1461, atexit auto-closes the sink — no manual flush required for CLI runs. See Custom Tracing for the underlying ContextTraceSinkProtocol.

Programmatic — LangfuseSink + Context Bridge

For full control over Langfuse tracing in Python code:
The set_context_emitter(... sink=sink.context_sink() ...) call is required for typical single-agent flows. Without it, only RouterAgent token-usage and PlanningAgent.plan_created events appear in Langfuse — Agent.start() lifecycle is silent.

LangfuseSinkConfig Options

OptionTypeDefaultDescription
public_keystr"" (then LANGFUSE_PUBLIC_KEY)Langfuse public key (pk-lf-...)
secret_keystr"" (then LANGFUSE_SECRET_KEY)Langfuse secret key (sk-lf-...)
hoststr"" (then LANGFUSE_HOSTLANGFUSE_BASE_URLhttps://cloud.langfuse.com)Langfuse server URL
flush_atint20Number of events that triggers a flush
flush_intervalfloat10.0Seconds between background flushes
enabledboolTrueMaster switch

CLI Server Commands


Common Patterns

Multi-Agent Tracing

All agents in a session share the same Langfuse context automatically:

Connection Verification

Configuration File Usage

Credentials from ~/.praisonai/langfuse.env are auto-loaded:

Best Practices

Call provider.flush() to ensure all traces are sent for obs.langfuse():
Path B (--observe langfuse) auto-registers atexit.close since PR #1461.
Prefer obs.auto() for environment-based configuration:
As of PR #1461, llm_response spans contain the assistant message text (or [tool_calls: name1, name2] summary), not the raw ChatCompletion(...) repr. The Langfuse “Output” panel is now human-readable:
  • Before: ChatCompletion(id='chatcmpl-...', choices=[Choice(...)], ...)
  • After: "The capital of France is Paris." or [tool_calls: search_web, calculator]
For programmatic usage, include the context emitter for complete lifecycle tracing:
Without this, only RouterAgent and PlanningAgent events appear — Agent.start() flows are silent.
When an agent runs the same tool concurrently (e.g. two parallel search_web calls), each TOOL_END event is now correlated to the matching TOOL_START via a per-(agent, tool) LIFO stack. Earlier versions could attach a TOOL_END to the wrong in-flight span. No user-facing API change — the fix is automatic.
Use CLI for local development:
  1. praisonai langfuse start
  2. praisonai langfuse config
  3. Test with praisonai langfuse test

Observability Overview

Compare observability providers

Agent Configuration

Configure agent settings