Langfuse tracing for Spring AI applications

Connect Java services built on Spring AI to your self-hosted Langfuse through OpenTelemetry, with the exporter, auth headers and prompt capture planned before the first trace.

On this page

How Spring AI traces reach a self-hosted Langfuse

Platform teams running Java services that call models through Spring AI usually want those calls recorded in their own Langfuse instance, not in a vendor-hosted account. The supported route is OpenTelemetry. Spring AI produces spans through the Spring Boot observability stack, and those spans are exported over OTLP to the /api/public/otel endpoint on your self-hosted Langfuse. Langfuse also accepts OpenTelemetry traces from other frameworks on the same endpoint, so the Spring AI setup is one instance of a general pattern rather than a separate product integration. Note that this is not a Langfuse SDK: there is no Langfuse client library to add to the service, and the application's telemetry configuration is what changes.

Three components have to be present for spans to leave the service. Spring Boot Actuator exposes the observability infrastructure, the Micrometer tracing bridge for OpenTelemetry connects Micrometer's observations to OpenTelemetry, and an OTLP exporter sends the finished spans to Langfuse. Confirm the exact artifact names, versions and compatible Spring Boot and Spring AI releases against the Langfuse Spring AI page and your own dependency management before you pin them, because the supplied material does not list them. Decide early which Langfuse project the services will write to, since the project credentials determine where the traces land.

Before you build, agree on three checks with the team that owns the Langfuse instance. First, confirm the public URL of the instance that the Java services can reach from their network segment, including any proxy or egress policy between them. Second, confirm how the OTLP authentication header is formed for your deployment and who issues the project keys. Third, decide whether prompt and completion content may be exported at all, because capturing message content is a configuration choice that changes what sensitive data reaches the trace store. Those three answers shape the configuration that follows.

What you need before exporting spans

Four things have to be in place before the Spring AI application can send spans: a running self-hosted Langfuse with a reachable OTLP endpoint, a Spring Boot service wired for Actuator and Micrometer tracing, project keys for authentication, and a network path with working TLS. Confirm each one before changing application code, so that a failed export can be traced to a single layer.

Running Langfuse with an OTLP endpoint

Langfuse accepts OpenTelemetry traces over OTLP at its /api/public/otel path, so the exporter must point at that path on your self-hosted host. Check that the instance is healthy and that Langfuse Web is serving the path before you touch the application. A trace that never appears is often a wrong base URL rather than a bad key. Ask your platform team which hostname the instance uses in your environment and whether a reverse proxy sits in front of it, since proxies can drop or rewrite requests.

OpenTelemetry docs

Spring Boot with Actuator and Micrometer

Spring AI spans reach the exporter through Spring Boot's observability stack, so the application needs Spring Boot Actuator and the Micrometer tracing bridge for OpenTelemetry. Without them, Spring AI produces no spans to export, and the application will look healthy while Langfuse stays empty. Confirm that the Spring Boot and Spring AI versions in your build match the combination described on the Langfuse Spring AI page, because observation naming and bridge artifacts change between releases.

Spring AI docs

Project API keys

Langfuse authenticates OTLP exports with a public and secret key pair from a specific project, so each service should use keys scoped to the project that owns its traces. Create the keys in the Langfuse project settings and store them in your secrets manager, not in application.yml committed to source control. Ask who may create and rotate keys in your organization, and plan how keys are replaced if a secret leaks, because every service using the pair must be updated together.

Network and TLS access

The application runtime must reach the Langfuse host over the network path your security team approved, and that path must present a certificate the JVM trusts. Check egress rules from the application subnet or pod network, DNS resolution for the Langfuse hostname, and whether a private certificate authority needs to be added to the Java truststore. Test connectivity from the same runtime that runs the service, because a laptop test often passes where the container fails.

Confirmed version combination

Spring Boot, Spring AI, the Micrometer tracing bridge and the OTLP exporter must be compatible with one another and with the Langfuse OTLP endpoint. Record the exact versions you plan to use and check them against the Langfuse Spring AI page before you start, since the page's guidance is the reference for this combination. If your organization pins versions through an internal bill of materials, confirm that the pinned versions match those instructions before the build is cut.

Spring AI docs

A test trace and a rollback path

Before enabling capture in production-like environments, plan a single test request that produces one known trace in a non-production Langfuse project. This confirms the full chain from application to Langfuse UI and gives the team a baseline to compare against. Decide in advance how the exporter is disabled if traces contain data that should not leave the application, since prompt and completion capture is the setting most likely to need a quick change.

Configure the Spring AI tracing pipeline in order

This sequence takes a Spring Boot service from no tracing to spans from Spring AI calls appearing in your self-hosted Langfuse project. Each step ends with a check you can run before moving on, so a failure is easy to locate.

  1. Confirm the Langfuse host and project keys

    Before touching the application, confirm the base URL of your self-hosted Langfuse instance and create or retrieve the public and secret keys for the target project in the Langfuse UI. Your platform team or whoever operates the instance can confirm the host name and whether it is reachable from the network where the Spring service runs. Check this by opening the host in a browser from that network and signing in; if the page loads and the project shows its keys, you are ready to configure the service.

  2. Add Actuator, Micrometer and OTLP dependencies

    In the service's build file, add Spring Boot Actuator, the Micrometer tracing bridge for OpenTelemetry and an OTLP exporter, along with the Spring AI starter your application already uses. Version alignment follows your Spring Boot and Spring AI baseline, so confirm the compatible versions in the Spring AI and Langfuse documentation before pinning them. Check this by building the project and confirming the dependencies resolve; the application should start without errors and expose the Actuator health endpoint locally.

  3. Point the OTLP exporter at the Langfuse endpoint

    Set the OTLP traces endpoint in application.yml or environment configuration to the Langfuse /api/public/otel path on your own host, using HTTPS if your instance terminates TLS. Keep the host value in configuration rather than in code so that the same build can run in development and production. Check this by starting the service and confirming in the logs that the exporter initializes with the expected URL, with no connection errors at startup.

  4. Build the authorization header from project keys

    Langfuse expects a Basic authorization header made from the project public key and secret key. Encode the pair as base64 in the form public key colon secret key, then pass it through the exporter's headers setting as the Authorization header. Store the secret in your secrets manager or environment variable, not in source control. Check this by confirming that the header value is present in the exporter configuration at startup without being printed in logs.

  5. Enable Spring AI observations

    Turn on observations for Spring AI chat and embedding calls so that model invocations emit spans, typically through the Spring AI observation settings in configuration. Confirm the exact property names for your Spring AI version in its documentation, since they change between releases. Check this by reviewing the configuration file and confirming that observation is enabled for the chat client you use, then leaving the service ready for a test call.

  6. Send a test call and confirm the trace

    Call an endpoint in your service that invokes the model once, such as a simple prompt through the chat client, and wait briefly for the exporter to flush. Open the Langfuse UI for the project and look for a new trace with the model span, its input and its timing. If nothing appears, check the endpoint path, the header encoding and the outbound network route from the service to Langfuse, in that order. The step is complete when the trace is visible in the project you configured.

  7. Decide what content is captured

    With the pipeline working, decide whether prompts and completions should be recorded in span attributes, since that is what makes traces useful for debugging but also what carries personal or confidential data into the trace store. Set the content-capture option only for the services and environments where your data handling rules allow it, and confirm the behavior with your security and privacy team. Check this by making one test call with content capture on and one with it off, and verifying in the Langfuse UI that the input and output appear or are absent as intended.

How a Spring AI call becomes a Langfuse trace

The trace starts when a client request reaches a Spring service that calls a model through Spring AI. Micrometer's tracing bridge hands the spans to OpenTelemetry, and the OTLP exporter sends them out of the application network to Langfuse's /api/public/otel endpoint. Langfuse Web accepts the traces and Langfuse Worker processes them into storage, so check that the exporter's destination and authentication headers reach the Web container through the trust boundary.

Spring AI spans crossing the trust boundary into self-hosted Langfuse.

Which Spring AI fields land where in Langfuse

This table maps parts of a Spring AI chat call, from the request trace down to token counts and message content, to where they appear in Langfuse. Read the third column before enabling prompt and completion capture in production, since message text may contain personal data. Attribute names can change, so confirm each one on the Langfuse Spring AI page before building dashboards or evaluations on it.

Span or fieldWhere it appears in LangfuseDepends on prompt or completion capture
Trace identityGroups the request handled by the Spring service and its child spansNot expected to depend on capture; confirm
Chat call observationSpring AI model call recorded as a child observation under the traceThe observation exists either way; its content fields do not
Model nameModel identifier reported by the chat client, used for model-level groupingNot expected to depend on capture; confirm
Token usagePrompt, completion and total token counts for cost and usage viewsNot tied to content capture, but the provider must return usage data
Input (prompt)Messages sent to the model, shown on the observation inputOnly populated when prompt capture is enabled
Output (completion)Model response text, shown on the observation outputOnly populated when completion capture is enabled
Application metadataUser, session and custom key values your code attaches to the traceSet by your code; not affected by capture settings
Timing and errorsSpan duration and status from Micrometer timing and exceptionsNot expected to depend on capture; confirm

Prompt and completion capture by environment

Development is where full capture helps most. Engineers need to see the exact prompt template, tool calls and completion to debug a chain, so many teams enable content capture on a local or shared test instance. The main risk is not the setting itself but the data: developers often paste real customer records into test prompts while troubleshooting.

  • Capture full content: Turn on prompt and completion capture so spans show the text the model received and returned.
  • Use synthetic or sanitized inputs: Keep production records out of local runs and shared sandboxes.
  • Separate the instance: Point developer applications at a separate self-hosted Langfuse deployment or project so their traces do not mix with production data.
  • Plan cleanup: Data retention policies need an Enterprise license key, so without one, agree how developer traces are deleted with your platform team.
  • Confirm the switch: Identify which content capture setting your Spring AI version exposes and test it with a single request before relying on it.

Check that a developer can reproduce a failing completion from a trace without any production data being involved.

Securing the trace path

Traces from a Spring AI service often carry user questions, model answers and internal document text, so the path from the application to Langfuse needs the same care as any other data flow. The cards below cover credentials, transport, export scope, personal data in prompts and read access to the stored traces.

Store project keys in a secret store

The OTLP exporter authenticates with a Langfuse public and secret key pair sent as an authorization header. Keep these values out of application.yml and source control, and inject them from your secret manager or the runtime environment at startup. Check that the secret key never appears in application logs, actuator output or container images, and plan a rotation step that updates every service exporting to the same project.

Encrypt the OTLP connection

Spans leave the JVM over HTTP to the /api/public/otel endpoint of your Langfuse Web deployment, so the exporter URL should use HTTPS when the collector and Langfuse sit on different networks. Confirm the certificate chain is trusted by the Java truststore of the service, and check that any internal load balancer or ingress in front of Langfuse terminates TLS with your approved certificates.

Limit which services can export

Each service that holds a project key can write traces into that project, so a misconfigured or compromised workload can add false data or flood ingestion. Use separate Langfuse projects with separate key pairs for applications with different owners or data classes, and restrict egress from the workload network so that only approved services reach the Langfuse host. Review this list when services are added or retired.

Reduce personal data in prompts

Spring AI instrumentation can capture prompt and completion content, which may contain names, account numbers or health details typed by users. Decide per application whether content capture is on, and where it is on, mask or drop fields in the request before the model call is traced. Confirm with your privacy team which categories of personal data are allowed in traces and document the rule for developers.

Review who can read traces

Trace views show full prompts, completions and metadata to anyone with access to the project, so access is a data control, not only a convenience setting. List the Langfuse users and roles that can open traces for each project and remove shared accounts. Self-hosted project-level RBAC roles and data masking are Enterprise license features, so confirm which of these your edition provides before you rely on them.

Langfuse license key docs

Why spans do not appear in Langfuse

This table lists the most frequent reasons Spring AI traces fail to reach a self-hosted Langfuse, with the cause and fix for each. Work through the rows in order, since the first two checks catch most setups before any network or header problem appears. Ingestion problems inside Langfuse itself belong to the operations group.

Symptom or checkLikely causeFix
No spans leave the applicationActuator or Micrometer tracing bridge for OpenTelemetry is missing from the buildAdd Spring Boot Actuator, the Micrometer tracing bridge for OpenTelemetry and an OTLP exporter, then rebuild and confirm the spans are created locally
Exporter sends to the wrong pathOTLP endpoint does not point at Langfuse's /api/public/otel path on your hostSet the exporter endpoint to your Langfuse base URL plus /api/public/otel and check the value in the deployed configuration, not only in local files
Requests return 401 or 403Authorization header is missing, malformed or carries keys from the wrong projectBuild the Basic credentials from the public and secret key of the target project and confirm the header reaches the exporter
Connection refused or timeoutContainer cannot reach the Langfuse host through the network, proxy or firewallTest connectivity from the application container or pod to the endpoint, then review proxy settings and egress rules with your network team
TLS or certificate errorsLangfuse is served with an internal certificate authority the JVM does not trustImport the internal CA into the Java truststore used by the service, and verify the chain with the same hostname the exporter uses
Traces appear but input and output are emptyContent capture is turned off in the instrumentation or the exporter configurationEnable prompt and completion capture deliberately, and review what personal data those fields will hold before turning it on in shared environments
Spans arrive but are accepted with no processingData reached the endpoint but the Langfuse side is backed up or failing to ingestCheck ingestion and worker health in the Langfuse operations and troubleshooting group, since the application side is working

Questions teams ask before connecting Spring AI to Langfuse

How much does it cost to connect Spring AI to a self-hosted Langfuse?

The cost is mostly the engineering time to add the Actuator, Micrometer tracing bridge and OTLP exporter to each service, test the spans, and agree how prompts are captured. The Langfuse software itself is MIT licensed for core features, so there is no license fee for the tracing path. Costs rise with the number of Spring AI services, custom spans, and review cycles with security and compliance teams. Ask any partner for a fixed-scope quote that lists the services in scope, the custom spans, the environments and the review steps, so you can compare it with your own team's estimate. Recurring costs are the infrastructure that runs Langfuse and the time to keep the Spring Boot and OpenTelemetry dependencies current.

How long does it take to get the first Spring AI trace into Langfuse?

The first trace depends mainly on whether a Langfuse instance already exists and whether the Java team can reach its OTLP endpoint from the application network. If Langfuse is already running, the first trace is usually a matter of adding dependencies, setting the endpoint and authentication headers, and calling a model in a test environment. If Langfuse must be deployed first, that work comes before any tracing. Timing also depends on your change process for dependency updates and network rules. Confirm the target environment, the Langfuse release in use and the approval steps before you set a date, and treat any duration you are given as a plan to check, not a promise.

What does the Java team need to do the work?

The Java team needs working knowledge of Spring Boot configuration, Spring AI model calls and Maven or Gradle dependency management. They must be able to add Spring Boot Actuator, the Micrometer tracing bridge for OpenTelemetry and an OTLP exporter, then set the exporter endpoint and headers through configuration rather than code where possible. They also need to decide which prompt and completion content is recorded. Engineers should understand how spans are created for each model call and how trace context passes between services. Plan time for code review and for testing with realistic but non-production data.

What does the platform team need to provide?

The platform team provides a reachable Langfuse endpoint, network rules from application subnets or clusters to that endpoint, and a managed way to issue and rotate the public and secret keys that go into the authentication headers. They also own the Langfuse deployment itself, including PostgreSQL, ClickHouse, Redis or Valkey and blob storage, and its capacity under load. If traces will cross a gateway, the platform team must confirm the gateway can pass OTLP traffic with the required protocol. Agree on who receives alerts when ingestion fails and where keys are stored, for example in your existing secrets manager.

Can an internal team set this up without a partner?

Yes, a Java team with Spring Boot experience and a platform team that already runs self-hosted services can usually do the basic setup internally. The Langfuse OpenTelemetry documentation and the Spring AI integration guide give the required building blocks. A partner is most useful when many services must be instrumented consistently, when custom spans or attribute schemas need design, or when security reviews require evidence. Decide which of these apply to you before you start. If your team has no recent experience operating Langfuse's data stores, consider a partner for the deployment side and keep tracing configuration in-house.

Will capturing prompts and completions expose personal or confidential data?

It can. Prompts and completions often contain customer names, account details, or internal documents, and once they are recorded as span attributes they are stored in your Langfuse deployment and its ClickHouse tables. Decide per service and per environment whether prompt and completion content is captured at all, and restrict capture to the data your use case needs. Your Langfuse deployment can also apply masking and retention, but some of those controls require an Enterprise license key, so check the license key documentation before relying on them. Limit who can read traces, and document the decision for your data protection and security reviews.

Which parts of the work usually cause delays?

The most common delays come from network approvals to reach the Langfuse endpoint, unclear ownership of API keys, and disagreement about prompt capture rules. Dependency version alignment between Spring Boot, Micrometer and the OpenTelemetry exporter also takes time when services use different parent POMs. Review cycles with security and privacy teams can take longer than the code change itself. Settle the capture policy, key storage and network path before development starts, and include a test pass in each environment that checks spans appear in Langfuse as expected. Ask any partner to list these dependencies in the written scope.

What changes for Java teams after the first trace

The first trace proves the pipeline works, but it does not settle who keeps it working. Treat the Spring AI, Micrometer tracing bridge, OTLP exporter and Spring Boot versions in each service as one set that someone owns. Check them against the Spring AI and Langfuse release notes before each upgrade, and confirm in your own environment that the Langfuse endpoint at /api/public/otel still accepts the exporter version you have pinned. Do not assume a version that worked last quarter still produces the same span attributes after a dependency bump.

Capture settings need the same discipline. Prompt and completion capture is usually switched on for debugging and then forgotten, so the decision about which services record message content, and in which environments, belongs in a written standard rather than in each team's configuration file. Keep the authentication header values in your secrets store, roll out the same capture and header configuration to every service through one shared template, and review it whenever a new service joins. Confirm with your security team how long captured prompts stay in Langfuse, because that retention is set on the Langfuse side and not in the Java code.

Schedule a trace review as part of every Langfuse upgrade. Major upgrades change the data model, so a span that rendered correctly before the upgrade may show different fields afterward. Before and after the upgrade, pick a few representative requests from each service, including a failing call and a tool-using call if your application has one, and compare what Langfuse shows. Record the result with the versions involved so that the next engineer can tell whether a gap in the traces came from the application, the exporter or the platform. The Langfuse upgrade guide is the starting point for planning that review.

How DeployOpen scopes and delivers this integration

DeployOpen approaches Langfuse tracing for Spring AI applications as a scoped piece of work inside your own infrastructure, starting from the services that call models and the self-hosted Langfuse instance that will receive their traces. The written scope fixes which services, endpoints and data handling rules are covered before any configuration begins.

How we scope

  • Inventory the Spring Boot services that call models and confirm which Spring AI paths they use.
  • Confirm the self-hosted Langfuse host, the OTLP endpoint and how project keys will be issued and stored.
  • Agree in writing whether prompt and completion capture is on, and which fields are masked or excluded.

How we build

  • Add Spring Boot Actuator, the Micrometer tracing bridge for OpenTelemetry and an OTLP exporter to each service.
  • Configure the exporter and authentication headers through externalized configuration, not hard-coded credentials.
  • Test spans in a non-production environment and check that traces appear in Langfuse with the expected attributes.

How we hand over

  • Document the configuration keys, header format, environment variables and the capture settings each service uses.
  • Walk your platform and application teams through the trace views and the troubleshooting steps for missing spans.
  • Hand over the configuration and runbook so your engineers can add new Spring AI services on their own.

How we support

  • Engagements are fixed-scope, with deliverables and timelines agreed in writing before work starts.
  • Ongoing support, upgrades and continuous testing are available as a retainer after handover.
  • Ask your DeployOpen contact to confirm which Spring Boot and Spring AI versions the scope covers.

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.