# Quarkus LangChain4j

Quarkus LangChain4j brings LangChain4j capabilities to the Quarkus framework, enabling AI development with native OpenTelemetry tracing for model interactions.

This guide covers routing telemetry from Quarkus LangChain4j applications to InteractiveAI using OpenTelemetry.

### Prerequisites

* InteractiveAI account with API credentials
* Java 21+
* OpenAI API key (or alternative model provider)

***

### Step 1: Enable OpenTelemetry in Quarkus

Add the Quarkus OpenTelemetry dependency to your `pom.xml`:

```xml
<dependency>
    <groupId>io.quarkus</groupId>
    <artifactId>quarkus-opentelemetry</artifactId>
</dependency>
```

Configure the OpenTelemetry exporter protocol in `application.properties`:

```properties
quarkus.otel.exporter.otlp.traces.protocol=http/protobuf
```

With this configuration, Quarkus LangChain4j records internal calls (such as chat model invocations) as spans. Each span includes attributes like `gen_ai.operation.name`, `gen_ai.system`, model identifiers, and token usage.

To capture prompt and response content, enable LangChain4j tracing in `application.properties`:

```properties
quarkus.langchain4j.tracing.include-prompt=true
quarkus.langchain4j.tracing.include-completion=true
```

***

### Step 2: Configure InteractiveAI

Direct OpenTelemetry data to InteractiveAI by configuring the OTLP endpoint and authentication in `application.properties`:

```properties
quarkus.otel.exporter.otlp.headers=Authorization=Basic <base64 of public_key:secret_key>
quarkus.otel.exporter.otlp.endpoint=https://app.interactiveai.com/api/public/otel
quarkus.otel.exporter.otlp.traces.protocol=http/protobuf
```

See the [OpenTelemetry](/integrations/native/opentelemetry.md) integration page for details on Basic Auth configuration.

***

### Step 3: Run an AI Operation

Start your Quarkus application and trigger an AI operation through a service that uses a `ChatModel`:

```java
@RegisterAiService(tools = EmailService.class)
public interface MyAiService {

    /**
     * Ask the LLM to create a summary about the given topic.
     *
     * @param topic the topic to summarize
     * @param sentences the number of sentences
     * @return the summary
     */
    @SystemMessage("You are a professional technical writer")
    @UserMessage("""
            Write a concise summary about {topic}. The summary should be {sentences} sentences long.
            Your response should only include the summary itself.
            """)
    String writeSummary(String topic, int sentences);
}

@Singleton
public class Startup {

    public void generateSummary(@Observes StartupEvent event, MyAiService service) {
        System.out.println(service.writeSummary("observability in AI systems", 3));
    }
}
```

***

### Running the Application

Configure environment variables:

```bash
export QUARKUS_LANGCHAIN4J_OPENAI_API_KEY=sk-proj-...

export QUARKUS_OTEL_EXPORTER_OTLP_ENDPOINT="https://app.interactiveai.com/api/public/otel"

export QUARKUS_OTEL_EXPORTER_OTLP_HEADERS="Authorization=Basic $(echo -n "pk-ia-xxx:sk-ia-xxx" | base64)"
```

Start the application:

```bash
./mvnw quarkus:dev
```

***

### Trace Visibility

The InteractiveAI dashboard displays:

* Chat model invocations with prompts and completions
* Token usage and model configuration
* Tool calls and service interactions
* Request latency and performance metrics


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.interactive.ai/integrations/ai-frameworks/quarkus-langchain4j.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
