Run This Ai
EN DE

Getting Started with Langfuse for LLM Observability: A Step-by-Step Tutorial

A hands-on tutorial for setting up Langfuse with Docker Compose, instrumenting your first LLM application with Python, and exploring the observability dashboard.

Langfuse Logo

Getting Started with Langfuse for LLM Observability

If you are building LLM-powered applications, understanding what your models are actually doing in production is critical. Langfuse provides a complete observability and evaluation platform that gives you deep visibility into every LLM call, agent step, and RAG retrieval — all from a clean, self-hosted dashboard. This tutorial walks you through setting up Langfuse and connecting your first application.

Prerequisites

  • Docker installed on your server or development machine
  • A Python or Node.js application using an LLM (OpenAI, Anthropic, open-source models)
  • Basic familiarity with environment variables

Step 1: Deploy Langfuse with Docker Compose

Create a docker-compose.yml file:

services:
  langfuse:
    image: langfuse/langfuse:latest
    restart: unless-stopped
    ports:
      - "3000:3000"
    environment:
      - NEXTAUTH_SECRET=your-secret-here
      - SALT=your-salt-here
      - DATABASE_URL=postgresql://postgres:***@db:5432/langfuse
      - TELEMETRY_ENABLED=false
    depends_on:
      db:
        condition: service_healthy

  db:
    image: postgres:15
    restart: unless-stopped
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
      POSTGRES_DB: langfuse
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U postgres"]
      interval: 5s
      timeout: 5s
      retries: 5

volumes:
  postgres_data:

Run: docker compose up -d. Langfuse will be available at http://localhost:3000.

Step 2: Configure Your First Project

  • Open the Langfuse dashboard and create an account (first user is admin)
  • Create a new project (e.g., "My LLM App")
  • Navigate to Settings → API Keys and generate a public/secret key pair
Langfuse Dashboard

Step 3: Instrument Your Python Application

Install the Langfuse Python SDK:

pip install langfuse openai

Add tracing to your OpenAI calls:

from langfuse import Langfuse
from openai import OpenAI

langfuse = Langfuse(
    public_key="pk-...",
    secret_key="sk-...",
    host="http://localhost:3000"
)

client = OpenAI()

# Create a trace for your LLM call
trace = langfuse.trace(name="my-rag-query")

# Log a generation
generation = trace.generation(
    name="openai-response",
    model="gpt-4o",
    input="What is Langfuse?",
    output="Langfuse is an open-source LLM engineering platform..."
)

Step 4: Explore the Dashboard

Back in the Langfuse UI, you will see your first trace appear in the Traces tab. From here you can:

  • Filter by model, user, or date range
  • Inspect individual trace details including latency and token costs
  • Create custom dashboards for your key metrics
  • Set up automated evaluations to score responses

Conclusion

You now have a fully self-hosted LLM observability stack running in minutes. Langfuse gives you the same level of insight into your AI applications that traditional APM tools provide for web services — tracing, metrics, evaluation, and debugging all in one place. As your application grows, explore Langfuse's advanced features: dataset management for regression testing, prompt versioning for controlled rollouts, and annotation queues for human-in-the-loop evaluation.

#langfuse #llm-observability #tutorial #docker #python