how-to

How to Integrate Langfuse with LangChain in 2026 - A Practical Guide

Wire Langfuse tracing into a LangChain or LangGraph app with a callback handler, see every chain and tool call in the dashboard, and add evals - plus the self-host gotcha and when Opik is the cheaper managed pick.

Published:

LangChain hides a lot of moving parts behind one .invoke() call - chains calling chains, tools firing, retrievers pulling context. When an answer comes back wrong, you need to see that whole tree, and Langfuse is the open-source default for doing it. The integration is a callback handler, and it takes about ten minutes.

This is the practical version - how to wire it up, what you get, the honest gotcha, and when Opik is the cheaper managed alternative.

Why Langfuse for LangChain

LangSmith is the most turnkey tracer for LangChain, but it is closed source, coupled to the LangChain stack, and expensive at volume - roughly $2,514/mo at 1M base traces on one seat per its pricing. Langfuse gives you the same nested-trace view of a LangChain run, but it is MIT-licensed, framework-agnostic, and dramatically cheaper - about $101/mo at 1M events, or free when self-hosted. For a LangChain app you want to keep past the prototype, that gap decides it.

The key point: you are not locked in. The Langfuse callback captures your LangChain traces today, and because Langfuse is framework-agnostic, the same backend traces the rest of your stack when you inevitably add something that is not LangChain.

Step 1: Get your keys

Sign up for Langfuse cloud (the free Hobby tier gives you 50k billable units a month with 30-day retention) or point at your self-hosted instance. Either way you get a public key and a secret key. Set them as environment variables so they are not hard-coded:

export LANGFUSE_PUBLIC_KEY="pk-lf-..."
export LANGFUSE_SECRET_KEY="sk-lf-..."
export LANGFUSE_HOST="https://cloud.langfuse.com"

If you self-host, LANGFUSE_HOST points at your own instance instead.

Step 2: Install the SDK

Langfuse ships a Python SDK and a JS / TypeScript SDK. For Python:

pip install langfuse langchain

Step 3: Add the callback handler

This is the whole integration. You create the Langfuse LangChain callback handler and pass it in the callbacks list when you run your chain. Every chain, tool and model call in that run is then captured as a nested trace:

from langfuse.langchain import CallbackHandler
from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate

langfuse_handler = CallbackHandler()

prompt = ChatPromptTemplate.from_template("Explain {topic} in one sentence.")
model = ChatOpenAI()
chain = prompt | model

chain.invoke(
    {"topic": "LLM tracing"},
    config={"callbacks": [langfuse_handler]},
)

That is it. You did not instrument a single function by hand - the handler hooks LangChain’s native callback system, so the prompt, the model call, token counts, latency and cost all land in the dashboard as one trace. The same pattern works for LangGraph agents: pass the handler in the config and every graph node and tool call shows up in the tree.

Step 4: Open the trace and read the tree

In the Langfuse dashboard each run appears as a nested trace - the chain at the top, the model call and any tool or retrieval steps underneath, each with inputs, outputs, latency and token cost. The point is the tree, not the log line. When a LangChain answer is wrong, you open the trace and see which step produced it - the retrieval that pulled bad chunks, or the prompt that confused the model - instead of guessing from flat logs. For the general version of this across any stack, see how to set up LLM tracing.

Step 5: Add evals on top

Tracing shows you what happened; evals score whether it was good. Langfuse layers LLM-as-judge and custom scorers, dataset management and human annotation queues onto the traces you are already capturing - so you can attach a quality score to each LangChain run and track it over time. This is where the observability platform pays off beyond raw traces.

The gotcha: hosting, not the integration

The LangChain wiring is smooth. The catch is where you run Langfuse. If you self-host, the v3 architecture needs Postgres plus ClickHouse, Redis and S3-compatible storage - four services to stand up, and the migration to that stack is where self-hosters hit memory errors and timeouts. The managed cloud sidesteps all of it. One more note: gRPC OTLP is not supported yet, HTTP only - though the LangChain callback path does not depend on OTLP at all, so it does not affect this integration. And file away that Langfuse became a ClickHouse subsidiary in January 2026, with the MIT license and self-host preserved.

The cheaper managed alternative: Opik

If you want managed hosting for less money, Opik integrates with LangChain too and its cloud is cheaper - $19/mo for 100k spans, the cheapest paid cloud of the major platforms, versus Langfuse Core at $29/mo. Opik is Comet’s platform, Apache-2.0 with the full feature set self-hosted and no gates, and it captures the same multi-step LangChain traces plus eval scoring. The trade-off is per-seat pricing that climbs as your team grows. For a small team that wants the cheapest hosted LangChain tracing, Opik is worth a look before you commit - the Opik vs Langfuse comparison weighs them head to head.

Which should you use?

  • You want the open-source default and can self-host, or you are fine on cloud Core - Langfuse. MIT, framework-agnostic, cheapest at scale when self-hosted.
  • You want the cheapest managed cloud for a small team - Opik at $19/mo, same LangChain trace capture.

Either way the LangChain integration is a callback handler and an afternoon of work. For the wider field of Langfuse competitors, see the Langfuse alternatives roundup. Code shape here follows the standard Langfuse callback pattern - verify method names against the current docs, since this category ships breaking changes monthly, and every pricing figure was read from each vendor’s own pages on 23 July 2026.

Frequently Asked Questions

How do I connect Langfuse to LangChain?

Langfuse provides a LangChain callback handler. You install the Langfuse SDK, set your public and secret keys, create the callback handler, and pass it in the callbacks list when you invoke your chain. From then on every chain, tool call and LLM call in that run shows up as a nested trace in the Langfuse dashboard - no per-function instrumentation needed. It works the same way for LangGraph.

Is Langfuse free to use with LangChain?

Yes, to start. Langfuse's cloud Hobby tier is free for 50k billable units a month with 30-day retention, which is enough to trace a small LangChain app in production. Self-hosting is free under MIT with only three features enterprise-gated. The paid Core tier is $29/mo for 100k units when you outgrow the free tier. There is no LangChain-specific charge - tracing a LangChain app costs the same as any other.

Do I need to change my LangChain code to use Langfuse?

Barely. The callback-handler approach means you add a few lines of setup and pass the handler in your invoke call - you do not rewrite your chains or wrap every function. Because it hooks LangChain's native callback system, every chain, tool and model call in the run is captured automatically. That is the same zero-config-per-step experience LangSmith gives on LangChain, but framework-agnostic and far cheaper at scale.

What is the catch with Langfuse and LangChain?

The integration itself is smooth - the catch is hosting. If you self-host Langfuse, the v3 architecture needs Postgres plus ClickHouse, Redis and S3-compatible storage - four services, and the migration is where people get stuck. The managed cloud sidesteps all of that. Also note gRPC OTLP is not supported yet, HTTP only, though the LangChain callback path does not depend on OTLP.

Explore More

Free Newsletter

Get the LLM Evals Newsletter

Platform comparisons, pricing changes and eval technique deep-dives. No spam.

Related Articles