A model's answer does not show which pipeline component supplied its prompt or where execution time went. Langfuse tracing gives a Haystack run a component tree, with the model call's input and response available beside its timing.
LangfuseConnector activates the integration when it is added to a pipeline. It uses a Langfuse project's public and secret keys to send observations to that project's host, while remaining separate from the connections that carry data between components. A named trace groups the executed components into one run.
Content tracing can send prompts, replies, and other component data to Langfuse, even when the model runs locally. Synthetic input is appropriate for the first run. A signed-in Langfuse account with an accessible project, permission to create its API keys, an active Python 3.11 or later environment, and a working Ollama model provide the starting point.
Steps to enable Langfuse tracing in Haystack:
- Select the intended project in Langfuse.
Haystack tracing is the project name shown here; your project can have another name. A project on Langfuse Cloud or an existing self-hosted instance works with the connector.
- Open Settings in the project sidebar.

- Select API Keys under Project Settings.

- Click Create new API keys.
The key pair grants API access to this project's tracing data. The secret belongs in a password manager or secret store, outside source control, shared terminals, and screenshots.
- Click Create API keys in the dialog.

- Record the displayed Public Key and Secret Key in your secret store.
The full secret is shown only once. A replacement pair is needed if it is lost. The Host Name on the General settings tab identifies the instance; its URL must be reachable from Python.
- Install the Langfuse integration in your active Python environment.
$ python -m pip install "haystack-ai==3.5.0" "langfuse-haystack==8.0.0" "langfuse==5.2.0"
These releases require Python 3.11 or later. An existing project should resolve these dependencies in its own environment before changing its lock file. The Ollama server must already have a downloaded model tag, such as qwen2.5:0.5b.
Related: How to create a virtualenv for Haystack
Related: How to run Ollama with Docker - Create haystack_langfuse.py in your text editor with the connection settings below.
Enabling content tracing exports component data, including prompts and replies, to the entered Langfuse host. Only data approved for that project belongs in traced runs. The secret prompt hides typing; the program keeps the key in process memory rather than in the file.
- haystack_langfuse.py
import os from getpass import getpass os.environ["LANGFUSE_HOST"] = input("Langfuse host URL: ").strip() os.environ["LANGFUSE_PUBLIC_KEY"] = input("Langfuse public key: ").strip() os.environ["LANGFUSE_SECRET_KEY"] = getpass("Langfuse secret key: ").strip() os.environ["HAYSTACK_CONTENT_TRACING_ENABLED"] = "true"
The host is the project's instance URL, without a project path or an /api suffix. A container needs an address reachable from its own network; 127.0.0.1 inside a container refers to that container. All four settings must exist before any Haystack import.
- Append the pipeline and connector imports after the environment settings.
from haystack import Pipeline from haystack.components.builders import ChatPromptBuilder from haystack.components.generators.chat import OpenAIChatGenerator from haystack.dataclasses import ChatMessage from haystack.utils import Secret from haystack_integrations.components.connectors.langfuse import LangfuseConnector
- Enable Langfuse tracing by adding the named connector below the imports.
pipeline = Pipeline() pipeline.add_component("tracer", LangfuseConnector("Haystack chat"))
The connector enables tracing during initialization. It is added without graph edges; only the components that exchange data need connections. Traces remain private by default. In an existing pipeline, this addition and the preceding settings enable tracing for its own components.
- Append the synthetic prompt component below the tracer.
pipeline.add_component( "prompt_builder", ChatPromptBuilder( template=[ChatMessage.from_user("In one short sentence, what color is a ripe banana?")] ), )
- Add the Ollama-backed generator below the prompt builder.
pipeline.add_component( "llm", OpenAIChatGenerator( api_base_url=input("Ollama API base URL (ending in /v1): ").strip(), model=input("Ollama model tag: ").strip(), api_key=Secret.from_token("ollama"), generation_kwargs={"temperature": 0, "max_tokens": 64}, ), ) pipeline.connect("prompt_builder.prompt", "llm.messages")
A host Python process normally reaches a local Ollama server at http://127.0.0.1:11434/v1. The model tag must match one downloaded by that server. The ollama token fills the client's required key field; it does not add authentication to Ollama.
- Finish the file with the pipeline run below the connection.
result = pipeline.run({"prompt_builder": {"template_variables": {}}}) print(result["llm"]["replies"][0].text)
The connector normally flushes observations after components finish. A generated reply confirms model execution, but a Langfuse trace must also arrive before the integration is working.
- Save haystack_langfuse.py.
- Run haystack_langfuse.py. Example output:
$ python haystack_langfuse.py ##### snipped ##### A ripe banana is a bright yellow color.The program prompts for the project host and key pair, then the Ollama API base URL and model tag. The model's wording can vary. An Ollama connection error means the endpoint cannot be reached from Python; a model-not-found error means that server lacks the tag. The reachable endpoint and downloaded tag are required before rerunning.
- Select Tracing under Observability in your Langfuse project.

- Open the new Haystack chat trace from the trace list.
A short ingestion delay can require refreshing the list. A Langfuse authentication error, including HTTP 401, means the host and key pair need checking against the same project. A connection error indicates an unreachable host or a network/TLS problem. A reply with no trace is not success; the original process needs the environment settings before its Haystack imports, and the project and time filter must include that run.
- Expand the trace detail with the Expand control.

- Confirm that the trace contains the executed prompt_builder, tracer, and llm components.
llm is recorded as a generation. An empty or unrelated trace does not show this run's components.
- Select the llm generation in the component tree.

- Verify that Preview shows the banana question under User and the generated reply under Assistant.
The reply must match the Python run. If only timing or metadata appears, content tracing may have been disabled when Haystack was imported; a fresh process with the setting enabled is needed. The matching component tree, prompt, and reply show that the pipeline reached the intended Langfuse project.