How Langfuse tracing for LangChain and LangGraph works
If your LangChain chains or LangGraph agents run in your stack and need traces in a self-hosted Langfuse, the supported method is the Langfuse CallbackHandler. It hooks into LangChain callbacks and captures LangChain executions, LLM calls, tool calls and retriever steps, and the same integration covers LangGraph agents. This is a code-side integration: your application creates the handler, passes it into the chain or graph invocation, and the handler sends trace data to the Langfuse host your team operates.
That placement decides who owns what. The application code needs the handler, the public and secret API keys for a project, and the host URL of your self-hosted Langfuse, normally set through environment variables so the same code runs in development and production without edits. Because the handler runs inside the process that calls the model, every trace originates from your application servers, so network egress from those workloads to the Langfuse host must be allowed and tested. Confirm the exact variable names and handler import path against the current integration docs for your LangChain and LangGraph versions, since these names change between releases.
Plan the callback as part of the application's configuration, not as a one-off debugging step. Decide which runs get the handler (all environments, or only staging and selected services), how user and session identifiers are attached so traces can be grouped, and who reviews what the traces contain. Prompts and completions are captured by default, so any personal data passed through an agent will appear in the Langfuse store, which is why the masking and retention settings described elsewhere on this page should be decided before the handler goes live.
What you need before tracing LangChain and LangGraph
Tracing LangChain and LangGraph into self-hosted Langfuse depends on four things lining up: a reachable Langfuse deployment, a project with keys, the framework packages your application already runs, and an SDK version your team has chosen. Confirm each one before changing application code, because most first-run failures trace back to a missing key, a wrong host or an untrusted certificate.
Running Langfuse Web and Worker
A self-hosted Langfuse runs two application containers, Langfuse Web for the UI and APIs and Langfuse Worker for asynchronous event processing, alongside PostgreSQL, ClickHouse, Redis or Valkey and blob storage. Confirm that both containers are healthy and that traces are accepted end to end. Ask the platform owner whether the deployment is a single-VM test setup or a production deployment, since that changes what you can expect from availability.
Self-hosting docsNetwork path from application to Langfuse
The application's runtime, whether a service, notebook or batch job, must be able to reach the Langfuse Web endpoint over the network. Check egress rules, proxies and DNS from every environment where LangChain or LangGraph runs, including development and CI. A trace that never leaves the application often looks like a code bug when the real cause is a blocked route.
Host URL and TLS trust
Set the Langfuse host URL to your own deployment, not a public default, and confirm the scheme and hostname match the certificate. If your organization uses an internal certificate authority, confirm with the platform owner that the application's runtime trusts that CA before tracing starts. Certificate errors in Python or Node often surface as silent export failures, so test with one simple chain first.
Project public and secret keys
Create a Langfuse project for the application and generate its public and secret keys in project settings. Store the secret key in your secrets manager or runtime secret store, not in source control or notebooks. Use separate projects or keys for development, staging and production so that trace data and access stay separated.
LangChain and LangGraph packages in use
Record the LangChain and LangGraph package versions your application already pins, and confirm the Langfuse integration works with them before upgrading either side. Keep framework upgrades and Langfuse SDK upgrades in separate changes when possible, so a regression can be traced to one of them. Agree which packages will be instrumented in each service.
SDK and Langfuse version alignment
Choose the Langfuse SDK version your team will standardize on, and check its minimum Langfuse server version in the SDK documentation and the Langfuse release notes. Current SDK majors can require a recent server release, so an older self-hosted instance may need an upgrade first. Confirm this before writing code, not after the first failed export.
Langfuse releasesConfiguring the Langfuse callback handler step by step
This sequence takes an application from no tracing to a LangChain chain and then a LangGraph agent with tool and retriever calls, with a visible check in the self-hosted Langfuse project after each stage. Each step produces an artifact the next one depends on.
Confirm the self-hosted Langfuse host and project
The platform team confirms the URL of the self-hosted Langfuse instance that developers will reach from their runtime, and creates or selects the project that will hold the traces. Confirm with your network team that the application hosts, including development and CI runners, can reach that URL over HTTPS. The step is done when a browser login to the project succeeds from a machine that will run the application.
Create project API keys
In the project settings, an authorized project member creates a public and secret key pair for the application. Store the secret key in your secrets manager rather than in source control, and use separate key pairs for development, staging and production so traces can be separated and keys can be revoked independently. The step closes when both keys are listed in the project, with the secret shown only once at creation.
Set host and key environment variables
Set the host and key values as environment variables in the application runtime, using the variable names the Langfuse LangChain integration documentation specifies for the public key, secret key and host. Pass them through your container, Kubernetes secret or CI configuration rather than hardcoding them. Confirm that the variables are visible to the process with a short startup check that prints only whether each variable is set, never its value.
Instantiate the CallbackHandler
In the application code, import the Langfuse CallbackHandler from the LangChain integration package and create one instance for the run. The handler reads the environment variables from the previous step, so no keys appear in code. Check the import and the package version against the Langfuse integration documentation, since the import path can differ between SDK releases. The step is done when the application starts without a configuration error.
Run a simple chain and confirm the trace
Pass the handler through the callbacks entry of the config argument when invoking a simple LangChain chain that calls one model. Run it once, then open the project in self-hosted Langfuse and find the new trace. The step closes when the trace shows the chain as the root, the model call as a generation with its input and output, and the timing of each span. If nothing appears, check the host value, the key pair and outbound connectivity from the application host first.
Extend the trace to a LangGraph agent
Build a small LangGraph agent with one tool and one retriever, and pass the same handler through the config on graph invocation. The handler propagates to the nodes, so no per-node instrumentation is needed for the covered steps. Run a question that forces the agent to call the tool. The step is done when the agent run appears as the root of the trace with the model calls inside it.
Verify tool and retriever spans
Open the agent trace and check that the tool call appears as a span nested under the agent run, with its arguments and return value visible. Then check that the retriever call appears as its own span and that its query and returned documents are shown. Missing spans usually mean the tool or retriever was called outside the callback chain, so review how the call was made if a step is absent. The step closes when every node you expected is visible with its inputs and outputs.
Review what the traces capture before wider use
Before the integration reaches other teams, the security and compliance owners review a sample trace for personal data, secrets in tool arguments and retrieved content that should not be stored. Decide whether masking or retention settings need to be configured, and confirm which of those features your license tier includes in the Langfuse documentation. The step is done when the reviewers have signed off on a sample trace and the findings are recorded against the project.
How LangChain and LangGraph runs reach your Langfuse
A user request enters your application, where LangChain or LangGraph runs LLM, tool and retriever steps. The Langfuse CallbackHandler emits events from inside that process and sends them to the Langfuse Web endpoint in your deployment, which hands work to the Worker. The Worker writes trace data to ClickHouse and blob storage. Check the trust boundary between your application network and the Langfuse deployment, since the callback traffic is the only data that crosses it.
Trace events flow from the LangChain run through the Langfuse Web endpoint and Worker into storage.
How LangGraph nodes, tools and retrievers map to Langfuse observations
A single LangGraph run becomes one trace in Langfuse, and each step inside that run becomes a nested observation. The Langfuse CallbackHandler, passed through the run configuration, records LangChain executions as the top-level span, then adds child observations for LLM calls (generations), tool invocations and retriever lookups as the graph moves between nodes. The nesting follows the callback hierarchy, so a graph node that calls a model and two tools shows those calls beneath the node's work rather than as a flat list. Before you write a mapping document for your team, confirm the current node, tool and retriever observation types and how they appear in the UI against the Langfuse LangChain and LangGraph integration docs, since the naming and grouping of graph steps can change between SDK and Langfuse versions.
Session, user and metadata values are attached through the run configuration rather than inside node code. The integration documents specific keys for these values, and the exact attribute names should be copied from the current docs and tested in a non-production project before you rely on them. Decide early which identifiers are safe to store in traces, such as an internal user ID or a conversation ID, and which must never reach the trace store. Metadata set at the run level propagates to child observations, so a single configuration change can tag every step of an agent run, which is useful for filtering by environment, graph version or tenant.
Managed prompts from Langfuse are linked to generations, so the prompt name and version used for each model call appear on the trace. This only works if the application fetches the prompt from Langfuse and passes the linked prompt object into the LLM call, instead of hard-coding the text in the graph. Scores are attached afterward through the Langfuse API or SDK, using the trace ID or observation ID returned by the run, which means your application must store those IDs with the graph output. Plan for this in the build: a graph that does not return its trace ID cannot be scored later without a lookup. Test both the prompt linkage and the scoring path in your self-hosted instance before you connect production traffic.
Data mapping between LangChain runs and Langfuse fields
This table compares each LangChain and LangGraph element with the Langfuse object it produces, where the value is set in application code, and what to check in the UI. Use it as a checklist after the first traced run, confirming that each row appears in the trace tree. User and session identifiers and prompt links depend on how the application passes metadata, so verify them early.
| Element and Langfuse object | Where it is set in the application | What to verify in the UI |
|---|---|---|
| Chain or graph run: trace | Pass the Langfuse CallbackHandler in the run config callbacks on the top-level invoke or stream call | One trace per top-level run, named after the chain or graph |
| LangGraph node: nested span | Recorded automatically for each node execution when the handler is attached to the graph run | Node spans appear in execution order under the trace |
| LLM invocation: generation | Model name comes from the chat model configuration; input and output come from the call | Model name, input, output and token usage are present on the generation |
| Tool call: span | Recorded automatically from the tool run; tool name and arguments come from the tool definition and call | Tool arguments, returned result and any error status appear on the span |
| Retriever call: retriever observation | Recorded automatically from the retriever invocation; the query comes from the retriever input | Query and returned documents appear; document content matches what the retriever returned |
| User identifier: trace user ID | Set through metadata in the run config; confirm the exact metadata key in the Langfuse LangChain docs | Filtering by a known test user ID returns the expected traces |
| Session identifier: trace session ID | Set through metadata in the run config, the same way as the user identifier | Sessions view groups the turns of one test conversation together |
| Prompt link: generation to managed prompt | Applies only when the prompt is fetched from Langfuse prompt management; confirm support for your SDK version | Generation shows the linked prompt name and version |
Securing traces that contain prompts and completions
A LangChain or LangGraph trace records whatever passes through the chain: prompts, model completions, retrieved documents and tool outputs. Each of those can carry personal or confidential data, so the trace store needs the same controls as the systems the data came from. The cards below cover the data risk, the keys that let applications write traces, and the masking, retention and capture settings that limit what gets stored.
Data that flows into traces
Traces capture more than the user's question. Retrieved documents, tool outputs, database rows and model completions all become span payloads, and any of them can hold customer records, credentials or internal material. Before go-live, list the chains and graph nodes that touch regulated data and decide which of their inputs and outputs are recorded in full, summarized or dropped. Ask whether tool responses from internal APIs are included, because these are often the largest and most sensitive payloads.
Secret keys in the runtime
The Langfuse public and secret keys are read by the application at runtime, usually through LANGFUSE_PUBLIC_KEY and LANGFUSE_SECRET_KEY. Store them in your secrets manager or orchestrator secret store, not in source control, container images or notebooks. Rotate keys when a developer leaves or a runtime is compromised, and confirm that log output from LangChain debug settings does not print them. Ask who can read the secret in each environment.
Least-privilege project keys
Create a separate Langfuse project for each application or environment, with its own key pair, so a leaked key exposes only one stream of traces. Avoid sharing one project across a chatbot, an internal agent and a test harness. Review which team members hold project roles in the Langfuse UI, since those roles control who can view trace content. Project-level RBAC roles are one of the features that need an Enterprise license key, so confirm this with your license before relying on it.
Server-side data masking
Server-side data masking lets the Langfuse instance redact sensitive fields before they are stored or displayed, which keeps masking logic out of each application. It is an Enterprise feature, so the team should confirm that its license includes it. Test masking with sample traces that contain representative identifiers, then check the trace view, the API responses and exports, since masking must hold across all three. Application-side redaction remains a backup for fields the masking rules do not cover.
License key docsRetention policies and deletion
Retention policies set how long traces remain in the instance before they are removed, which limits how long personal data persists. Data retention policies need an Enterprise license key. Choose periods with your data protection owner based on the purpose of the traces, and confirm that deletion also reaches backups and ClickHouse data according to your backup design. Document the policy so auditors can compare it with what the instance actually does.
Limiting capture in the application
Before the first production run, decide which inputs the callback handler should record. Options include excluding specific chain or node runs from tracing, truncating large tool outputs, and sending only identifiers rather than full user records as metadata. Limiting capture at the source is the only control that stops sensitive data from leaving the application, so it complements masking and retention. Test each change with a trace review, since a skipped step can hide the context needed for debugging.
LangChain integration docsWhy LangChain traces are missing or incomplete
This table lists the failures teams most often hit when LangChain or LangGraph traces do not appear in self-hosted Langfuse, with the likely cause and a check the team can run in its own environment. Work through the rows in order, since host and key problems hide every other symptom.
| Symptom | Likely cause | How to check and fix |
|---|---|---|
| Project stays empty | Wrong host, or keys from a different project or instance | Confirm the host URL matches your self-hosted web address and that the public and secret keys belong to the project you are viewing. Run one simple chain and check the request reaches the host. |
| Only the outer call appears | Handler not passed through callbacks, so nested LLM, tool and retriever runs are not reported | Pass the handler in the config callbacks list on each invoke or stream call, or set it as a default for the runnable. Confirm child spans appear under the root trace. |
| LangGraph nodes missing | Handler attached only to the top-level graph in some setups, so node-level calls are not captured | Include the handler in the config used when invoking the compiled graph and check that node invocations inherit it. Compare a run with a single node against the full graph. |
| Traces appear late or not at all in scripts | Asynchronous runs or short-lived processes exit before buffered events are flushed | Call the client flush method before the process exits, including after errors. In serverless or batch jobs, verify flushing in a test run before relying on the trace data. |
| Worker backlog delays traces | Langfuse Worker is processing events slowly, so traces are visible only after a delay | Check Worker container load and queue health in your monitoring. Langfuse recommends scaling worker containers on CPU load, so confirm capacity with your operations team. |
| TLS errors from the SDK | Internal certificate authority not trusted by the application runtime | Add your internal CA to the trust store used by the Python or Node process, then test the host with a single request. Do not disable certificate verification as a fix. |
Questions teams ask before connecting LangChain or LangGraph to Langfuse
How much effort is it to add Langfuse tracing to an existing LangChain app?
For most teams the core change is small: add the Langfuse CallbackHandler to the callbacks passed to your chains, graphs or agents, and set the Langfuse host and API keys in the environment. The effort grows with what you need the traces to carry. Capturing LLM, tool and retriever steps comes largely for free through the callback, but linking managed prompts, attaching user and session identifiers, and scoring runs add code in each path that matters. Ask the partner for a written scope that lists the chains and graphs in question, so the quote reflects the real work rather than a generic estimate. The LangChain and LangGraph integration docs describe the handler and its coverage.
What makes the integration take longer?
Several factors drive the effort up:
- The number of chains, graphs and agents, since each entry point needs callbacks wired and checked
- Custom tools and retrievers, which may need explicit naming or metadata to be readable in traces
- Async code paths, where callbacks must be passed consistently through awaited calls and background tasks
- Multiple environments, such as development, staging and production, each with its own host and keys
- Masking requirements, because deciding what may leave the application and how it is redacted takes review with your security and privacy teams
Each factor is one-time work during build, but masking decisions also shape ongoing operations. Ask the quote to name which of these apply to your codebase.
Can one in-house engineer set this up using only the documentation?
Often yes for a small, single-service LangChain application with a running Langfuse instance, because the handler setup is documented and well contained. The harder parts are rarely the import statement. They include deciding what metadata and identifiers to attach, handling async and streaming code correctly, and confirming that traces appear as expected in every environment. Teams with several services, strict data handling rules or no spare capacity to review traces usually find a second pair of hands useful. Treat the documentation as the reference for the first working trace, and plan a separate review for the production configuration.
What do you need to provide before the work starts?
The work depends on four inputs from your side:
- A running self-hosted Langfuse instance, with its web address reachable from the application environments
- Key management: a process to create project API keys, store them in your secrets system and rotate them
- Access to the application code for the LangChain or LangGraph services in scope
- A test environment where traces can be generated safely, with representative but non-sensitive inputs
Your team also needs to name an owner for trace data decisions, including what may be captured. Confirm access and key handling early, since they often set the schedule more than the code change does.
How long does it take to verify that tracing works?
Verification has two stages. The first confirms that a sample run produces a trace in Langfuse with the expected LLM, tool and retriever steps. The second confirms that the production configuration behaves correctly, including keys per environment, masking, and the scoring or prompt links you intend to use. The first stage is usually short, while the second depends on how many paths need checking and how quickly your reviewers can sign off. The duration is not fixed by any supplied source, so ask the partner to state the verification steps and their timing in the written scope.
Do LangGraph agents need separate setup from LangChain chains?
No separate integration is needed for LangGraph in the sense that the same Langfuse callback approach covers it, according to the Langfuse integration documentation. The engineering question is how the handler is passed through the graph's nodes and invocations so that each run, including branches and tool calls, appears in one coherent trace. Agents that loop or run long sessions need particular attention to session and user grouping. Ask for a test plan that exercises the graph paths you use in production, not only a single happy-path run.
Does the tracing setup need a Langfuse Enterprise license?
Tracing through the LangChain callback handler is part of the core features that Langfuse describes as available in its MIT-licensed open source version. Features such as project-level RBAC roles, protected prompt labels, data retention policies, audit logs and server-side data masking need an Enterprise license key. If your masking or retention requirements depend on server-side controls, confirm which of those features you need before choosing a configuration, because client-side redaction in the application is a separate decision. Check the Langfuse license key documentation for the current list.
How DeployOpen scopes and delivers this integration
DeployOpen treats LangChain and LangGraph tracing as a platform integration, not a code drop. We plan where the self-hosted Langfuse instance runs, how the callback handler reaches it from your applications, and how traces, prompts and scores are governed inside infrastructure you control, then build and hand over the result in writing.
How we scope
- Inventory which LangChain chains and LangGraph agents will send traces, and which environments they run in
- Agree the Langfuse host, network path and key ownership for each project in writing before build starts
- Define which LLM, tool and retriever steps must be captured, and which inputs must be masked or excluded
- Engagements are fixed-scope, with scope, deliverables and timelines agreed in writing before work starts
How we build
- Wire the Langfuse CallbackHandler into chains and graphs using keys and host settings from environment configuration, not source code
- Confirm that tool and retriever spans appear with the expected nesting, inputs and outputs in a self-hosted test project
- Link managed prompts to the runs that use them and check that prompt versions are recorded on each trace
- Add scoring hooks for runs so evaluations attach to the traces they judge, then test them against sample conversations
How we hand over
- Deliver a written configuration guide covering environment variables, host settings, project keys and callback setup per service
- Document which graph nodes and chain steps produce spans, and the known gaps in coverage for your framework versions
- Provide a verification checklist that your engineers can rerun after each LangChain or LangGraph upgrade
- Transfer operational runbooks for rotating keys, changing the Langfuse host and reviewing trace content
How we support
- Ongoing support, upgrades and continuous testing are available as retainers after handover
- Re-test tracing coverage when LangChain or LangGraph versions change, since span structure can shift between releases
- Review trace content periodically against your data handling rules, including what reaches Langfuse from each agent
- Ask any partner to confirm support terms, response expectations and SLAs in the written scope before signing

