Integrating Langfuse with Quarkus LangChain4j
This guide shows how to integrate Langfuse with Quarkus LangChain4j using OpenTelemetry.
Quarkus LangChain4j: A Quarkus based integration of LangChain4j for AI development with built-in OTel tracing for AI calls.
Langfuse: Open source LLM engineering platform for observability, evals and prompt management.
Please raise an Issue on GitHub if you face any issues with this integration.
Step 1: Enable OpenTelemetry in Quarkus LangChain4j
Add Quarkus OpenTelemetry Dependency (Maven):
For Maven, add the following to your pom.xml
(Gradle users can include equivalent coordinates in Gradle):
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-opentelemetry</artifactId>
</dependency>
Configure OpenTelemetry exporter (application.properties
):
quarkus.otel.exporter.otlp.traces.protocol=http/protobuf
With these configurations and dependencies in place, your Quarkus application is ready to produce OpenTelemetry traces. Quarkus LangChain4j internal calls (e.g. when you invoke a chat model) will be recorded as spans.
Each span will carry attributes like gen_ai.operation.name
, gen_ai.system
(the provider, e.g. “openai”), model names, token usage, etc., and – since we enabled them – events for the prompt and response content
Step 2: Configure Langfuse
Now that your Quarkus application is emitting OpenTelemetry trace data, the next step is to direct that data to Langfuse.
Langfuse will act as the “backend” for OpenTelemetry in this setup – essentially replacing a typical Jaeger/Zipkin/OTel-Collector with Langfuse’s trace ingestion API.
Langfuse Setup
- Sign up for Langfuse Cloud or self-hosted Langfuse.
- Set the OTLP endpoint (e.g.
https://cloud.langfuse.com/api/public/otel
) and API keys.
Configure these via environment variables:
QUARKUS_OTEL_EXPORTER_OTLP_ENDPOINT: set this to the Langfuse OTLP URL (e.g. https://cloud.langfuse.com/api/public/otel).
QUARKUS_OTEL_EXPORTER_OTLP_HEADERS: set this to Authorization=Basic <base64 public:secret>.
You can find more on authentication via Basic Auth here.
Step 3: Run a Test AI Operation
Start your Quarkus application. Trigger an AI operation that Quarkus LangChain4j handles – for example, call a service or controller that uses a ChatModel
to generate a completion.
Note: A complete example can be found here
@RegisterAiService(tools = EmailService.class)
public interface MyAiService {
/**
* Ask the LLM to create a poem about the given topic.
*
* @param topic the topic of the poem
* @param lines the number of line of the poem
* @return the poem
*/
@SystemMessage("You are a professional poet")
@UserMessage("""
Write a single poem about {topic}. The poem should be {lines} lines long and your response should only include the poem itself, nothing else.
Then send this poem by email. Your response should include the poem.
""")
String writeAPoem(String topic, int lines);
}
@Singleton
public class Startup {
public void writeAPoem(@Observes StartupEvent event, MyAiService service) {
System.out.println(service.writeAPoem("LangFuse", 4));
}
}
Troubleshooting
No Traces:
- Check the logs of the application for potential clues
- Check Troubleshooting page