Observability · Kubernetes

Self-hosting Langfuse: notes from running it on Kubernetes

ClickHouse migrations, missing spans, misleading cost totals, and using MCP to investigate the traces once they arrive.

Our most memorable Langfuse storage problem was ClickHouse writing 288 GiB of its own internal trace logs in a day. The system recording what our agents did had taken up recording itself.

We run Langfuse on EKS to trace VoiceScript’s transcript-processing agents: each job’s model calls, tool calls and guardrails, with timings, token usage and outputs. Staging is now on Langfuse 4.59.0, and almost all the work of getting there was in the database and the trace exporter, not the web app. These are the notes I would want for the next install, plus a workflow for letting a coding agent read traces through MCP.

Langfuse staging dashboard showing trace counts by workflow, model costs and observations over time, with dollar amounts pixelated.
The staging dashboard over the past 30 days. Dollar amounts are pixelated; they are model usage priced by Langfuse, not the cost of hosting it. Click any screenshot to enlarge.

Give ClickHouse its own lifecycle

The Helm chart’s bundled ClickHouse is one replica with ZooKeeper: a single point of failure, no backups, and images from Bitnami’s legacy registry. We moved it to the Altinity operator, with one shard, two replicas and three ClickHouse Keeper members, and pointed Langfuse’s web and worker deployments at it. PostgreSQL, the Redis-compatible queue (we use Dragonfly) and S3 stay separate. That is a lot of systems, and two replicas give you availability, not backups.

The cutover order that worked:

  1. Stop new ingestion, and decide what clients do with events sent meanwhile.
  2. Let the worker finish outstanding jobs. An empty queue is not enough; check active work too.
  3. Stop the writer.
  4. Run the schema migrations on the new cluster.
  5. Copy history across.
  6. Point web and worker at the new cluster.

In chart v2 values the connection looks like this, with credentials from a Kubernetes Secret:

clickhouse:
  deploy: false
  host: clickhouse-langfuse-clickhouse
  httpPort: 8123
  nativePort: 9000
  database: default
  cluster:
    enabled: true

Older values used a flat clusterEnabled key, so check the chart’s schema. When we moved an existing release into Helmfile, we captured its live values first and got to a no-op diff before upgrading anything. Changing who owns the config and changing the app in separate steps made both easier to debug.

Three ClickHouse surprises

Bound the internal logs. After the 288 GiB day we set query_log, part_log and trace_log to seven days’ retention. Adding a TTL element alone failed with the operator, because its generated engine definition already had the table settings; we replaced the whole per-log engine definition, TTL included, in an override loaded after the generated files. Keep watching disk and ClickHouse’s own metrics too: at a high enough write rate even a day of logs is too much, and pod health will not tell you.

Migrations may ignore your cluster name. In v3.150.0 the clustered migrations hardcoded ON CLUSTER default, and CLICKHOUSE_CLUSTER_NAME did not change that. Naming the operator’s cluster default was the simplest fix. If a correct-looking connection fails only in migrations, look for this.

Backfills need more memory than steady state. The v4 migration produced merges of about 3.1 GiB, against about 500 MiB before. One replica kept running out of memory repeating a merge the other had already finished. Raising the memory request from 2 GiB to 4 GiB (limit 8 GiB) and setting

merge_tree/prefer_fetch_merged_part_size_threshold: "104857600"

made merges over 100 MiB prefer fetching the finished part from the other replica, which stopped the loop. It is one input to ClickHouse’s merge selection, not a guarantee, but it was enough here.

Upgrading to v4

Cross-replica queries failed authentication during the v4 backfill, a path ordinary v3 traffic never used. The operator’s cluster needed an interserver secret for distributed queries, which secret.auto: "true" provides.

We ran dual writes, backfilled, and reconciled counts before switching to events_only on 16 October: 29,162 historical traces became root spans and 604,111 observations became events. Matching counts is the gate, but spot-check trace structure and recent ingestion as well.

Clients have to move with the server. v4 retires the legacy ingestion and read endpoints and needs Python SDK 4 or JavaScript SDK 5, so the v3-to-v4 upgrade guide belongs in the plan for every script and service that reads or writes traces, not just the deployment.

Backups are daily fulls and four-hourly incrementals to S3, on an s3_plain disk so a restore does not depend on the original pod’s local object index. The test that counts: seed a table, back it up, drop it, restore it across the cluster and check both replicas. A successful upload proves much less.

Make sure the workers actually export spans

Our agents set workflow names and metadata, but deployed workers sent no traces. The Langfuse client was only initialised on a CLI start-up path, so workers never registered the exporter. We moved initialisation into the shared runtime bootstrap, made it idempotent, and log whether tracing is on. Our wrapper also maps LANGFUSE_BASE_URL to whatever host setting the installed SDK reads: a host setting that is silently ignored falls back to Langfuse’s hosted service, not your instance.

Shutdown is the other trap. KEDA scales the workers, and OpenTelemetry batches spans, so a worker can finish its queue and get SIGTERM with spans still buffered. Flush after each job and on graceful shutdown, or the last model call of a successful job goes missing.

To test an integration, follow one identifiable job end to end: the worker’s start-up log, the trace, its generation and guardrail spans, then the same again while the worker scales down. An authentication check tells you much less than one complete trace.

Langfuse tracing view filtered to root observations, showing workflow names, status and latency. Input, output and metadata columns are hidden.
The v4 tracing view, root observations only, with input, output and metadata columns hidden. A root row can show no cost even when its child generation has one.

A zero cost can mean a missing price

Our apps report LiteLLM model aliases, and some did not match Langfuse’s built-in pricing, so that traffic looked free. We added project-level model definitions for the exact names the apps emit. Cached input and reasoning tokens can also arrive under their own usage keys; if a key has no price, totals undercount even when input and output rates are right. Before trusting a cost graph, check one generation’s model string, usage keys and calculated cost, and review custom prices when providers or aliases change.

Reading traces through MCP

The browser is good for looking at one trace. MCP helps when the question starts in the code, such as “which step made this workflow slow, and where is it implemented?”, because a coding agent can pull the observations into the same context as the source.

Connect to the authenticated project-data MCP server, not Langfuse’s documentation MCP. On a self-hosted instance it is at:

https://langfuse.example.com/api/public/mcp

Use Streamable HTTP with an Authorization: Basic header holding the base64 of PUBLIC_KEY:SECRET_KEY, the project’s API keys. Base64 is not encryption, so keep it in the client’s secret store, and allow only read tools for investigations. Behind a proxy, preserve the public Host header or allow the extra hosts explicitly. Setup is in the MCP documentation.

In v4, listObservations returns a trace’s observations. Check the connected server’s tool schemas first, since the deployed version is the authority; the current reference needs explicit start-time bounds even with a trace ID, at most 14 days per request, and a pagination cursor. getObservationFieldSchema and getObservationFilterSchema list valid fields and filters. Fetch compact records first and pull inputs and outputs only when needed. For the trace pictured below:

{
  "traceId": "0a08e4d6ed7efdd0b36fd470eb727dc3",
  "fromStartTime": "2026-10-16T00:00:00Z",
  "toStartTime": "2026-10-17T00:00:00Z",
  "limit": 50
}

Then give the agent a bounded task:

Investigate this trace using read-only Langfuse tools. Retrieve every page of observations in the supplied time window. Reconstruct the parent-child relationships and identify the critical path. Report model-call duration, retries, token usage and recorded cost where available. Cite observation IDs for each finding, then locate the corresponding code. Separate what the trace proves from hypotheses that need logs or another run. Do not change prompts, scores or datasets.

Asking for evidence first stops an agent seeing a slow parent span, deciding orchestration is expensive, and optimising the wrong code.

Reporter Summary trace tree: the root takes 7.18 seconds and its nested response takes 7.03 seconds. Costs are pixelated.
A trace from staging, costs pixelated. The root has no input or output of its own, but the tree still shows the nested agent, turn, response and guardrail steps.

Here the root takes 7.18 seconds and the nested response 7.03. The agent and turn spans in between show about 7.04 seconds because they contain the same work, so adding them up would count it three times. The model call is about 98% of the wall time, which points the next look at the model, not orchestration. It does not say why the call took seven seconds: prompt length, provider queuing, output length and retries each need their own evidence, and one slow trace is not a regression until you compare similar requests. A green status means the step finished, not that its summary was right.

If I were installing it again

  • Run ClickHouse outside the chart, under an operator, with backups you have restored from.
  • Cap ClickHouse’s internal log tables on day one, and alert on disk.
  • Name the ClickHouse cluster default unless you have checked the migrations.
  • Give migrations and backfills more memory than steady state, and watch merges.
  • Initialise tracing in the worker’s own start-up path, and flush on shutdown.
  • Test with one real job, end to end, including a scale-down.
  • Check model names and usage keys against prices before trusting cost totals.
  • Upgrade every client alongside the server.