Langfuse tracing for LlamaIndex RAG applications

Connect LlamaIndex retrieval pipelines to self-hosted Langfuse through the OpenInference instrumentation and the OTLP endpoint, so retrieval and synthesis spans can be inspected and scored.

On this page

Tracing LlamaIndex RAG pipelines into self-hosted Langfuse

When a RAG application gives wrong answers, the failure is usually in one of several places: the query was rewritten badly, the retriever returned the wrong chunks, or the model ignored good context. Langfuse traces LlamaIndex through the OpenInference LlamaIndex instrumentation, which captures LlamaIndex operations and exports them as OpenTelemetry spans to the /api/public/otel OTLP endpoint of your self-hosted Langfuse. Once those spans land in Langfuse, the retrieval and synthesis steps can be inspected side by side for each question. The Langfuse LlamaIndex integration guide describes the setup steps.

The OpenInference instrumentation is a third-party library, not a Langfuse-maintained SDK integration, so its attribute names and span shapes are set by its own project and can change between releases. This page covers only the supported path: the OpenInference instrumentor, the OpenTelemetry exporter pointed at your Langfuse host, and the Langfuse authentication headers. Before you rely on it, confirm which OpenInference package version your LlamaIndex version requires, check that your Langfuse version accepts OTLP traces, and test with a non-production project so you can see which spans arrive and how they are named.

Plan the endpoint and credentials before instrumenting. The OTLP exporter needs your Langfuse host, a project's public and secret keys and the encoded authorization header that Langfuse expects, so keys should come from a secret store rather than from source code. Confirm that the application can reach the Langfuse web service on your network, and that traffic from development and production uses separate projects so debugging data does not mix with customer traces. Retrieval traces can contain user questions and document text, so decide with your privacy team what gets captured before the first production run.

What a LlamaIndex tracing setup needs before the first span

A LlamaIndex application only produces useful traces once four things are in place: a reachable self-hosted Langfuse, project keys that route spans to the right project, an application environment with pinned instrumentation packages, and network paths from the application to Langfuse. Confirm each one before you change application code, because a missing piece usually shows up as silent empty traces rather than an error.

A running, reachable Langfuse host

Confirm that your self-hosted Langfuse instance is up and that the HTTPS hostname the application will call resolves and presents a valid certificate from the machines that run your RAG service. Check the host from the application's own network segment, not from your laptop, since internal DNS, proxies and private certificate authorities often differ between the two. Ask your platform team whether the Langfuse web tier is the endpoint that receives OTLP traffic in your deployment, and record the exact base URL so every environment uses the same value.

Self-hosting docs

Project API keys per environment

Create a separate Langfuse project, with its own public and secret key pair, for each environment that runs the LlamaIndex application, such as development, staging and production. Store the keys in your secret manager and inject them as environment variables rather than hardcoding them in source. Keeping environments in separate projects stops test queries from mixing with production traces and makes it simpler to apply retention or access rules per environment.

Pinned LlamaIndex and instrumentation versions

Pin the LlamaIndex core package, its retrieval and LLM integrations, the OpenInference LlamaIndex instrumentation and the OpenTelemetry packages in your dependency lock file. Instrumentation libraries change how they name spans and attributes, so an unpinned upgrade can change what your dashboards and evaluations see. Confirm the exact package names and compatible releases against the Langfuse LlamaIndex page and your application's own dependency constraints before you install anything.

Langfuse LlamaIndex page

Application environment and configuration

Decide where the Langfuse host, public key and secret key are read at startup, and make sure the RAG service fails loudly when they are missing. Set the OTLP exporter to send to Langfuse's OpenTelemetry endpoint with the authorization header your Langfuse version expects, and verify those values in each container image or deployment manifest. Make the instrumentation initialize before LlamaIndex objects are created, since spans from earlier calls are not captured.

Egress from the application to Langfuse

The RAG service must be allowed to reach the Langfuse host on HTTPS from its runtime location, which may be a Kubernetes namespace, a VM subnet or a serverless network. Check outbound firewall rules, egress proxies, NAT gateways and any service mesh policy, and test with a request to the OTLP endpoint before deploying. If your security policy restricts egress, ask the network team to document the destination and port so the change is reviewed once rather than discovered during an incident.

Langfuse OpenTelemetry docs

Data handling review before traces flow

RAG traces contain the user question, retrieved document chunks and generated answers, which can include personal or confidential data from your corpus. Before enabling tracing in production, agree with the data owners what may be stored, how long traces are kept and who can view them in Langfuse. Confirm whether your Langfuse edition provides the masking and retention controls you need, because these may depend on your license tier.

How to instrument a LlamaIndex pipeline step by step

This sequence takes a self-hosted Langfuse project from empty to a first LlamaIndex trace, so your team can confirm that retrieval and synthesis are captured before instrumenting the rest of the application.

  1. Create a project and API keys in Langfuse

    An administrator signs in to your self-hosted Langfuse, creates a project for the RAG application, and generates a public key and a secret key for it. Keep the secret key in your secrets manager rather than in source control, and record the base URL of your instance. The step is done when the project appears in the project list and both keys are stored where the application can read them.

  2. Set the OTLP endpoint and Basic authentication header

    The application needs the OpenTelemetry endpoint of your instance, which Langfuse exposes at /api/public/otel under your base URL. Build a Basic authentication header from the public and secret keys as described in the Langfuse OpenTelemetry documentation, then set the endpoint and header as environment variables such as OTEL_EXPORTER_OTLP_ENDPOINT and OTEL_EXPORTER_OTLP_HEADERS. Confirm the exact variable names and encoding against the current docs for your SDK version. The step is done when the values load in the runtime without being printed to logs.

  3. Install the OpenInference LlamaIndex instrumentor

    A developer adds the OpenInference instrumentation package for LlamaIndex, together with the OpenTelemetry SDK and OTLP exporter packages, to the same environment as the RAG application. OpenInference is a third-party library, so pin its version and record it in your dependency lock file. The step is done when the packages import cleanly in the environment that runs your pipeline.

  4. Register the tracer provider before queries run

    The developer calls the instrumentor's register and instrument step at application startup, before any index is built or query engine is created. This configures a tracer provider that exports spans over OTLP to Langfuse and patches LlamaIndex so its operations emit spans. Registering it after the first query means that call is not traced. The step is done when the startup code runs once and logs no export errors.

  5. Run one test query against the pipeline

    The developer runs a single known question through the query engine, using a document the team already understands so the answer can be checked by hand. The run should include retrieval and response synthesis so both kinds of work are exercised. Wait for the export to complete, since spans are sent asynchronously. The step is done when the query returns an answer in the application and no error appears in the console.

  6. Confirm the trace with retriever and LLM spans

    In the Langfuse UI, an engineer opens the Traces view for the project and finds the trace for the test query. The trace should show a retrieval span with the query and returned nodes, and an LLM span with the prompt and completion. If only a generic span appears, or no trace appears, check the endpoint, the header and whether the tracer provider was registered before the query. The step is done when both span types are visible and their inputs match the test query.

How a RAG query travels from LlamaIndex to Langfuse

The trace starts in the application, where a call to the LlamaIndex query engine runs retrieval against the vector store and then a synthesis call to the LLM. The OpenInference instrumentor turns each of those operations into OpenTelemetry spans, which leave the application network over OTLP to the /api/public/otel endpoint of your self-hosted Langfuse. Check that the trust boundary is where you expect it, since the spans carry prompts, retrieved text and answers.

Retrieval and synthesis spans cross one trust boundary into self-hosted Langfuse.

Which LlamaIndex operations appear as which Langfuse observations

This table maps common LlamaIndex retrieval, synthesis and model operations to the Langfuse observation types and attributes they usually produce through the OpenInference instrumentation. Read it as a starting hypothesis, then confirm each row against the instrumentation version you run, because span names and attribute keys change between releases. The main takeaway is that retrieval spans carry the query and the retrieved node IDs and scores, which is where most RAG debugging starts.

LlamaIndex operationExpected Langfuse observationKey attributes to checkWhat to verify
Query engine call (end-to-end question)Parent trace or root span wrapping the requestUser query text, final response, session or user identifiers if you set themConfirm the root span appears once per user question and not once per internal step
Retriever (vector or hybrid search)Retriever observationQuery string, top-k setting, retrieved node IDs, similarity scoresConfirm scores and node IDs are populated in your version and that content is not truncated
Embedding calls for the query and nodesEmbedding observationEmbedding model name, input text reference, token usage where the provider returns itCheck whether token counts are captured and whether cost mapping exists for your embedding model
Response synthesizer or rerankerSpan or chain observation under the queryNode inputs passed to synthesis, reranker scores, output textVerify how reranker inputs are represented, since this varies by node postprocessor
LLM completion or chat callGeneration observation nested under the queryModel name, prompt and completion messages, input and output token counts, latencyConfirm model name matches your pricing configuration so cost is calculated in Langfuse
Custom or unsupported componentsGeneric span or missing observationWhatever the instrumentation records by defaultTest with a trace and check for gaps before relying on the dashboard for those steps

Using retrieval spans to find why answers are poor

The first diagnostic question for a poor RAG answer is whether the model ever saw the right text. In a Langfuse trace of a LlamaIndex application, the retriever span and the LLM span answer that question side by side. Open the trace, check which chunks the retriever returned for the query and whether the passage that contains the answer is among them. If it is missing, the failure sits in retrieval: the chunking, the embedding model, the top-k setting, metadata filters or the index itself. If the right chunk is present and the answer is still wrong, the failure sits in synthesis: the prompt, the response mode, the model or the context window. Confirm which fields the OpenInference instrumentation writes to each span in your version, since the names of retrieval attributes and similarity scores can differ between releases and between LlamaIndex versions.

Read the two spans in order, every time. For retrieval failures, look at the returned node texts, their source metadata and any similarity scores the span exposes, and compare them with the document you expected to match. A low score on the correct passage points to the embedding model or query phrasing. A high score on an irrelevant chunk points to chunk boundaries that split the answer or to a missing filter. For synthesis failures, paste the exact context that reached the LLM span into your review and check whether the answer contradicts it, ignores it, or combines it with outside knowledge. Those are different fixes, and mixing them up wastes a sprint.

Illustrative example: a policy question returns a retriever span whose top three chunks come from an outdated handbook, while the current policy chunk ranks fifth. The fix is in retrieval, such as re-indexing with metadata or adjusting top-k, not in the prompt. Review traces grouped by query type (for example, policy lookups, calculations and multi-document comparisons) rather than in one random sample. A failure rate that looks acceptable overall can hide a query class where retrieval never works. Export the grouped examples into your evaluation set so each fix is tested against the queries that failed.

Protecting prompts, retrieved documents and keys in traces

Traces from a RAG pipeline hold retrieved documents, prompts and answers, so access to them is a data governance question as well as a debugging one. The controls below work together: decide what is captured, mask or expire it where your license allows, scope keys and access to one project, and keep every hop encrypted. Enterprise items are marked and need a license key.

Treat retrieved chunks as sensitive data

Retriever spans often carry full document passages, customer records or internal policy text, and the same text is copied into the synthesis prompt and the final answer. Treat the trace store as a copy of your document corpus. Before you enable capture, classify the indexes that feed the pipeline and confirm with your data owners whether passage text may be stored in ClickHouse at all.

Mask content on the server

Server-side data masking is an Enterprise license key feature in self-hosted Langfuse. Because it is applied by the Langfuse server, it can cover traces from applications you have not yet changed, including retrieved passages and generated answers. Test it with a sample document that contains a known identifier, and confirm which fields it covers and whether masked values still work for evaluations.

License key docs

Set retention for trace history

Data retention policies are also an Enterprise license key feature. Retrieved passages can persist in trace history long after an investigation ends, so set a retention period that matches the classification of the indexed documents before production traffic arrives. Ask how deletion reaches ClickHouse, blob storage and exports, and record the answer for your compliance file.

Scope API keys to one project

Create a separate Langfuse project for each RAG application and environment, and issue its API key pair only to that project. A leaked key then exposes one trace stream, and rotation affects a single service. Store keys in your secrets manager, never in notebooks or source control, and rotate them when someone with access changes roles. Project-scoped keys are part of the open source feature set.

Send traces only over TLS

Send traces only to the HTTPS address of your self-hosted Langfuse. Span payloads contain full prompts, retrieved passages and answers, so plaintext OTLP would expose them on the network. Check the exporter endpoint in every LlamaIndex service, since a copied example may point to a different host, and confirm that your load balancer or ingress rejects plain HTTP on the OTLP route.

OpenTelemetry docs

Limit project viewers with RBAC

Project-level RBAC roles are an Enterprise license key feature. Trace viewers can read retrieved text and generated answers, so limit project access to the team that operates the pipeline. Confirm which roles your instance offers before inviting reviewers from other departments, check the permissions in your own instance before you rely on them, and review membership whenever someone changes teams.

Why LlamaIndex traces are missing or incomplete

This table lists the failures teams most often hit when LlamaIndex traces do not reach a self-hosted Langfuse, or arrive with gaps. Each row gives the likely cause and the fix, so you can check the simplest explanation first. Confirm limits and behavior against the OpenInference LlamaIndex instrumentation version you run, since span coverage changes between releases.

SymptomLikely causeFix
No traces appear at allThe instrumentor was registered after the first queries ran, so those calls were never wrappedRegister the OpenInference instrumentor and the OTLP tracer provider once, at process startup, before building or querying any index
No traces appear and the exporter logs an errorWrong OTLP endpoint path or a missing Authorization header with the Langfuse project keysPoint the exporter at your host's /api/public/otel path and send the Basic authentication header built from the public and secret keys for the same project
Export fails with a certificate errorThe Langfuse host uses a certificate from an internal certificate authority that the application runtime does not trustAdd the internal CA bundle to the runtime's trust store or configure the exporter's certificate path, and avoid disabling verification
Retriever or query spans are missing in async codeAsync query paths such as aquery or async retrievers were not covered by the instrumentation version in use, or spans were not closed before the process exitedConfirm async coverage for your version, flush the tracer provider before exit in batch jobs, and compare sync and async runs on the same input
Traces appear, but only some steps showCustom retrievers, query engines or tools were built outside the instrumented LlamaIndex classesAdd manual spans around custom components, or confirm which component types the instrumentation wraps for your version
Traces arrive minutes lateThe Langfuse worker is saturated, so asynchronous event processing falls behind ingestionCheck worker CPU load and queue behavior, scale worker containers, and review the scaling guide before changing the application
Traces are dropped during load testsExporter batch limits or the worker queue overflow under bursts of concurrent queriesTune batch export settings, reduce test concurrency for a baseline, and confirm limits with the instrumentation and Langfuse version in use
Traces show the wrong project or userKeys from another project or environment were loaded from an old configuration fileRead keys from a single environment source, verify the project in the Langfuse UI, and rotate any key that was shared outside its project

Questions teams ask before connecting LlamaIndex to Langfuse

What drives the cost of adding LlamaIndex tracing to self-hosted Langfuse?

The cost depends mainly on how much application code has to change, how many pipelines need tracing, and how much evaluation design is included. Instrumenting one LlamaIndex application with the OpenInference instrumentation is a small code change, but the surrounding work adds up: credentials handling for each environment, deciding which span attributes to keep, and building evaluations that score retrieval and answer quality. Each additional pipeline repeats the review of inputs and outputs. Ask any quote to list these items separately, so you can see which part is one-time setup and which part recurs when pipelines change.

Can one in-house engineer connect LlamaIndex to Langfuse alone?

Often yes for a single pipeline, provided that engineer can reach the Langfuse host and understands the RAG application's code. The core steps are installing the OpenInference LlamaIndex instrumentation, configuring the OpenTelemetry exporter to send spans to the Langfuse OTLP endpoint at /api/public/otel, and confirming that retrieval and synthesis spans appear. The harder parts are usually outside the code: agreeing what user content may be stored in traces, setting up keys per environment, and designing evaluations that the team will maintain. A single engineer can do the technical steps, but security and data owners still need to sign off on the content decisions.

What does our team need to provide before the work starts?

Three inputs matter most. First, access to the self-hosted Langfuse host, including project creation and API key issuance, plus network access from the RAG application's environments to the endpoint. Second, a test RAG pipeline with representative documents, queries and an index, so spans can be checked against realistic retrieval behavior without using production data. Third, a written decision on what content may be stored: whether full prompts, retrieved chunks and generated answers are logged, or only metadata and identifiers. Teams that delay the third decision often rework their instrumentation later, so settle it before the build begins.

How long does LlamaIndex tracing take to set up?

Duration depends on scope rather than on a fixed number. A single application with one retrieval pipeline and an existing Langfuse host is the shortest case. Duration grows with the number of pipelines, the number of environments that need separate keys, the amount of metadata to standardize across services, and whether evaluations are included. Access approvals on the Langfuse host and the content decision often take longer than the code change itself. A fixed-scope proposal should state the milestones and what each one depends on, and it should name the team's inputs as dependencies.

Does a self-hosted Langfuse license change how LlamaIndex tracing works?

No. The LlamaIndex integration uses the OpenInference instrumentation and the OTLP endpoint, and Langfuse states that all core features and APIs are available in the MIT-licensed open source version without limits. Self-hosted deployments use the same codebase as Langfuse Cloud. The Enterprise license key matters for governance features such as project-level RBAC roles, data retention policies, audit logs, server-side data masking and SCIM provisioning. If your RAG tracing needs those controls, the license affects the surrounding deployment, not the instrumentation itself. Confirm the license terms in the repository's LICENSE file and the license key documentation before you rely on any feature.

Which trace data should we avoid storing in Langfuse?

Retrieved chunks and user queries often contain personal data, customer records or confidential documents, and LlamaIndex traces capture them by default in many setups. Decide early which attributes to suppress or hash, whether to log full synthesis prompts, and how long traces stay in ClickHouse. Server-side data masking and retention policies are Enterprise features, so if you need them, confirm that before the design is final. Also ask your compliance team which obligations apply to trace content, since the answer shapes what the instrumentation should record.

What should a RAG evaluation cover once traces are flowing?

Start with the questions you need the traces to answer: did retrieval return the right chunks, did synthesis use them, and did the answer match the source. Traces show each retrieval and synthesis step, so you can compare the retrieved context with the final response for poor answers. Evaluation design, including which judge model, scoring rubric and human review sample you use, is a separate decision with its own effort. Ask any proposal to name the evaluation scope explicitly, because a trace-only engagement and a trace plus evaluation engagement differ in both work and ongoing upkeep.

Who maintains the tracing setup after go-live?

The application team owns the instrumentation code, and the platform team owns the Langfuse host, its upgrades and its capacity. Instrumentation breaks when LlamaIndex or the OpenInference package changes, so pin versions and review them during dependency updates. Langfuse upgrades that change the data model or infrastructure follow separate migration guides, so keep the instrumentation and the host versions on a tested path. Ongoing support can be handled in house or through a retainer, and the choice depends on how often pipelines change and who is on call for them.

How DeployOpen scopes and delivers LlamaIndex tracing

DeployOpen is a Chainscore Labs company that plans, deploys and supports self-hosted Langfuse inside the client's own infrastructure, and most engagements for this work are fixed-scope. Scope, deliverables and timelines are agreed in writing before work starts, so the instrumentation of your LlamaIndex pipelines, the Langfuse deployment it sends traces to and the evidence your security team receives are all defined up front. The quote follows from that written scope. DeployOpen does not publish a price list, so the reader should expect the scope document to name the pipelines in scope, the environments involved and the review artifacts to be produced.

For a RAG application, a typical written scope covers the LlamaIndex retrieval and synthesis paths to instrument, the OpenInference instrumentation and OTLP export to the /api/public/otel endpoint of the self-hosted instance, the handling of user and session attributes, and the trace review needed to debug weak answers and set up RAG quality evaluations. It can also cover the controls a security or compliance reviewer will ask about, such as where prompts and retrieved document text are stored, who can view traces and how long they are kept. Ask DeployOpen to state which of these are included, and which assume an existing Langfuse deployment that you already run.

Retainers are available for work that continues after go-live, such as Langfuse version upgrades, monitoring of ingestion and retrieval quality, and periodic security testing of the RAG application. Ask for the retainer terms in writing, including what is covered, how requests are handled and what is excluded. Ask for the same for any evidence package intended for a customer AI security review or internal assessment: DeployOpen prepares systems, controls and evidence, but independent auditors and certification bodies issue any audit reports or attestations.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.