Quarkus LangChain4j
cetra traces Quarkus LangChain4j AI services through the quarkus-opentelemetry extension: the AI service call, each model call and each tool execution land in one trace.
Install
Section titled “Install”<dependency> <groupId>io.quarkiverse.langchain4j</groupId> <artifactId>quarkus-langchain4j-openai</artifactId> <version>1.15.1</version></dependency><dependency> <groupId>io.quarkus</groupId> <artifactId>quarkus-opentelemetry</artifactId></dependency>The fixture was captured with the Quarkus platform 3.40.1.2, imported as io.quarkus.platform:quarkus-bom in dependencyManagement.
Set up
Section titled “Set up”Point the exporter at cetra and turn the content switches on in application.properties:
quarkus.langchain4j.openai.api-key=${OPENAI_API_KEY}quarkus.otel.exporter.otlp.endpoint=http://localhost:8080quarkus.otel.exporter.otlp.headers=Authorization=Bearer sk-cetra-…quarkus.otel.exporter.otlp.traces.protocol=http/protobufquarkus.otel.service.name=my-appquarkus.langchain4j.tracing.include-prompt=truequarkus.langchain4j.tracing.include-completion=truequarkus.langchain4j.tracing.include-tool-arguments=truequarkus.langchain4j.tracing.include-tool-result=truequarkus.otel.exporter.otlp.endpointis a base URL: Quarkus appends the signal’s path itself.- The four
include-*switches turn the content on. They are off by default: without them the model calls carry no prompt, completion, tool arguments or tool result.
Declare the AI service and the tool:
import dev.langchain4j.agent.tool.P;import dev.langchain4j.agent.tool.Tool;import io.quarkiverse.langchain4j.RegisterAiService;import jakarta.enterprise.context.ApplicationScoped;
@RegisterAiService(tools = WeatherTools.class)public interface Assistant { String chat(String message);}
@ApplicationScopedpublic class WeatherTools { @Tool("Get the current weather for a city") public String get_weather(@P("city") String city) { return "Sunny in " + city + ", 21 C"; }}What you get
Section titled “What you get”One AI service call with one tool round:
- a plain span for the AI service call, named after the interface and the method,
langchain4j.aiservices.Assistant.chat; - an
llmspan namedcompletion <model>for each model call, with the provideropenai, the model, the token counts and the cost computed from the built-in prices; the input is the prompt and the output is the completion, as plain text; - a
toolspan namedlangchain4j.tools.<tool>, with the arguments as its input and the result as its output; - a plain
POST /chat/completionsspan from the HTTP client under each model call.
Limits
Section titled “Limits”- Content is off by default: the four
include-*switches turn on the prompt, the completion, the tool arguments and the tool result. - The model call’s input and output are plain text, not parsed messages.
- The turn that answers with a tool call writes no completion, so its
llmspan has an input but no output. The prompt of the following call then showsnullin place of the model’s tool call; that is how Quarkus serializes the conversation. - The HTTP client spans stay plain spans; cetra reads no model data from them.
- The capture sent no Authorization header; the header setting above is the library’s documented option, not part of the captured run.
- The fixture was captured with Quarkus 3.40.1.2 and Quarkus LangChain4j 1.15.1.
- If a field is missing, look at the span’s Attributes tab and compare it with Span attributes.
- Send OpenTelemetry: the endpoint and the headers cetra expects.
- Traces: read the trace as a tree and a timeline.
- Cost and tokens: how cost is computed from the token counts.