Deploying a Langfuse App
Introduction
Langfuse is an open-source observability and analytics platform for LLM applications. Deploying Langfuse with a Dockerfile on Klutch.sh gives you reproducible builds, managed secrets, and persistent storage for telemetry and metadata—all configured from klutch.sh/app. This guide covers installation, repository prep, a production-ready Dockerfile, deployment steps, Nixpacks overrides, sample API usage, and production best practices.
Prerequisites
- A Klutch.sh account (create one)
- A GitHub repository containing your Langfuse code/config (GitHub is the only supported git source)
- Docker familiarity and Node.js 18+ knowledge (Next.js-based)
- PostgreSQL credentials
- Storage for logs and optional cache
For onboarding, see the Quick Start.
Architecture and ports
- Langfuse serves HTTP; set the internal container port to
3000. - PostgreSQL should run as a separate Klutch.sh TCP app, exposed on port
8000and connected internally on5432. - Persistent storage is optional (for logs/cache) but recommended if you store artifacts locally.
Repository layout
langfuse/├── Dockerfile # Must be at repo root for auto-detection├── package.json├── pnpm-lock.yaml # or yarn.lock / package-lock.json├── .env.example # Template only; no secrets└── README.mdKeep secrets out of Git; store them in Klutch.sh environment variables.
Installation (local) and starter commands
Install dependencies and run locally before pushing to GitHub:
pnpm installpnpm buildpnpm start -- --port 3000Optional helper start.sh for portability and Nixpacks fallback:
#!/usr/bin/env bashset -euo pipefailpnpm migrate:deploy || truepnpm start -- --port 3000Make it executable with chmod +x start.sh.
Dockerfile for Langfuse (production-ready)
Place this Dockerfile at the repo root; Klutch.sh auto-detects it (no Docker selection in the UI):
FROM node:18-alpine AS buildWORKDIR /app
COPY package.json pnpm-lock.yaml* yarn.lock* package-lock.json* ./RUN corepack enableRUN pnpm install --frozen-lockfile
COPY . .RUN pnpm build
FROM node:18-alpineWORKDIR /appENV NODE_ENV=production PORT=3000
COPY --from=build /app /appRUN corepack enable && pnpm install --prod --frozen-lockfile
EXPOSE 3000CMD ["pnpm", "start", "--", "--port", "3000"]Notes:
- Add build tools (
apk add --no-cache python3 make g++) in the build stage if native modules are needed. - Keep Next.js output within the image; static assets are served directly.
Environment variables (Klutch.sh)
Set these in the Klutch.sh app settings (Secrets tab) before deploying:
NODE_ENV=productionPORT=3000DATABASE_URL=postgres://<user>:<password>@<host>:<port>/<db>NEXTAUTH_URL=https://example-app.klutch.shNEXTAUTH_SECRET=<secure-secret>LANGFUSE_HOST=https://example-app.klutch.shLANGFUSE_PUBLIC_KEY=<public-key>LANGFUSE_SECRET_KEY=<secret-key>
If you deploy without the Dockerfile and need Nixpacks overrides:
NIXPACKS_BUILD_CMD=pnpm install --frozen-lockfile && pnpm buildNIXPACKS_START_CMD=pnpm start -- --port 3000NIXPACKS_NODE_VERSION=18
These keep Langfuse compatible with Nixpacks defaults when a Dockerfile is absent.
Attach persistent volumes
In Klutch.sh storage settings, add mount paths and sizes (no names required):
/app/.next/cache— optional cache for faster rebuilds./app/logs— optional if you store logs locally.
Ensure these paths are writable inside the container.
Deploy Langfuse on Klutch.sh (Dockerfile workflow)
- Push your repository (with the Dockerfile at the root) to GitHub.
- Open klutch.sh/app, create a project, and add an app.
- Connect the GitHub repository; Klutch.sh automatically detects the Dockerfile.
- Choose HTTP traffic for Langfuse.
- Set the internal port to
3000. - Add the environment variables above (database, NextAuth, Langfuse keys, and any
NIXPACKS_*overrides if you temporarily deploy without the Dockerfile). - Attach persistent volumes for
/app/.next/cache(and/app/logsif used), selecting sizes that fit your caching/logging needs. - Deploy. Your Langfuse instance will be reachable at
https://example-app.klutch.sh; attach a custom domain if desired.
Sample ingestion request
Send an event to Langfuse (replace placeholders):
curl -X POST "https://example-app.klutch.sh/api/public/ingest" \ -H "Content-Type: application/json" \ -H "x-langfuse-public-key: <public-key>" \ -H "x-langfuse-secret-key: <secret-key>" \ -d '{"events":[{"type":"trace","id":"trace_123","name":"demo-trace","timestamp":1690000000}]}'Health checks and production tips
- Add a reverse proxy probe to
/api/healthor a lightweight status route. - Enforce HTTPS at the edge; forward HTTP to port 3000 internally.
- Keep lockfiles committed and Node version pinned; test upgrades before applying.
- Monitor database performance and set connection pool limits to match your Postgres deployment.
- Rotate keys and secrets regularly; store them only in Klutch.sh secrets.
Langfuse on Klutch.sh combines reproducible Docker builds with managed secrets, optional persistent cache/log storage, and flexible HTTP/TCP routing. With the Dockerfile at the repo root and port 3000 configured, you can run observability for your LLM apps without extra YAML or workflow overhead.