From 8e7528bc75bc2a24bfa3ee3f6a69a3fd178bc8db Mon Sep 17 00:00:00 2001 From: Omar Atie Date: Sat, 29 Aug 2026 12:48:14 -0700 Subject: [PATCH] Add Spring Boot genai-observability example Spring Boot sample for Camel GenAI observability with langchain4j-chat, camel-ai-observability, and docker-compose stack (Prometheus, VictoriaTraces, Perses) aligned with camel-test-infra-observability. Co-authored-by: Claude Opus 4.6 Co-authored-by: Cursor --- pom.xml | 1 + spring-boot/genai-observability/README.adoc | 68 +++++++++++++ .../genai-observability/docker-compose.yml | 20 ++++ spring-boot/genai-observability/pom.xml | 97 +++++++++++++++++++ .../genai-observability/prometheus.yml | 16 +++ .../genai/GenAiObservabilityApplication.java | 28 ++++++ .../src/main/resources/application.properties | 29 ++++++ .../resources/camel/genai-route.camel.yaml | 24 +++++ spring-boot/pom.xml | 44 +++++++++ 9 files changed, 327 insertions(+) create mode 100644 spring-boot/genai-observability/README.adoc create mode 100644 spring-boot/genai-observability/docker-compose.yml create mode 100644 spring-boot/genai-observability/pom.xml create mode 100644 spring-boot/genai-observability/prometheus.yml create mode 100644 spring-boot/genai-observability/src/main/java/org/apache/camel/example/genai/GenAiObservabilityApplication.java create mode 100644 spring-boot/genai-observability/src/main/resources/application.properties create mode 100644 spring-boot/genai-observability/src/main/resources/camel/genai-route.camel.yaml create mode 100644 spring-boot/pom.xml diff --git a/pom.xml b/pom.xml index 895ab3505..14fc08548 100644 --- a/pom.xml +++ b/pom.xml @@ -132,6 +132,7 @@ spring spring-pulsar spring-xquery + spring-boot telegram timer transformer-demo diff --git a/spring-boot/genai-observability/README.adoc b/spring-boot/genai-observability/README.adoc new file mode 100644 index 000000000..4d2044192 --- /dev/null +++ b/spring-boot/genai-observability/README.adoc @@ -0,0 +1,68 @@ += Spring Boot GenAI Observability Example + +== Introduction + +This example demonstrates *GenAI observability* in Apache Camel 4.23+ with Spring Boot: +OpenTelemetry `gen_ai.*` span attributes and Micrometer metrics for `langchain4j-chat` +LLM calls, visualized with Prometheus and VictoriaTraces. + +It pairs with the community blog post *GenAI Observability with Spring Boot and the Camel Observability Stack*. + +=== Prerequisites + +* Java 17+ +* Maven 3.9+ +* Docker (for observability stack) +* https://ollama.com/[Ollama] with `llama3.2` pulled + +== Build + +[source,shell] +---- +mvn compile +---- + +== Run + +Terminal 1 — Ollama: + +[source,shell] +---- +ollama pull llama3.2 +ollama serve +---- + +Terminal 2 — observability stack (Prometheus + VictoriaTraces + Perses): + +[source,shell] +---- +docker compose up -d +---- + +Terminal 3 — Spring Boot application: + +[source,shell] +---- +mvn spring-boot:run +---- + +== Verify GenAI observability + +[source,shell] +---- +curl -s http://localhost:8080/actuator/prometheus | grep gen_ai +---- + +* Prometheus: `http://localhost:9090` +* VictoriaTraces: `http://localhost:9428/select/vmui` +* Perses: `http://localhost:8088` + +== Help and contributions + +If you hit any problem using Camel or have some feedback, then please +https://camel.apache.org/community/support/[let us know]. + +We also love contributors, so +https://camel.apache.org/community/contributing/[get involved] :-) + +The Camel riders! diff --git a/spring-boot/genai-observability/docker-compose.yml b/spring-boot/genai-observability/docker-compose.yml new file mode 100644 index 000000000..710347738 --- /dev/null +++ b/spring-boot/genai-observability/docker-compose.yml @@ -0,0 +1,20 @@ +# Observability stack for Camel GenAI observability blog (Blog 2) +# Images aligned with camel-test-infra-observability + +services: + prometheus: + image: quay.io/prometheus/prometheus:v3.13.2 + ports: + - "9090:9090" + volumes: + - ./prometheus.yml:/etc/prometheus/prometheus.yml:ro + + victoriatraces: + image: mirror.gcr.io/victoriametrics/victoria-traces:v0.10.0 + ports: + - "9428:9428" + + perses: + image: mirror.gcr.io/persesdev/perses:v0.54.0 + ports: + - "8088:8080" diff --git a/spring-boot/genai-observability/pom.xml b/spring-boot/genai-observability/pom.xml new file mode 100644 index 000000000..93f629b9c --- /dev/null +++ b/spring-boot/genai-observability/pom.xml @@ -0,0 +1,97 @@ + + + + + 4.0.0 + + + org.apache.camel.example + camel-examples-spring-boot-parent + 4.23.0-SNAPSHOT + + + camel-example-spring-boot-genai-observability + jar + Camel :: Example :: Spring Boot :: GenAI Observability + Spring Boot example for Camel GenAI observability with LangChain4j and Ollama + + + Observability + + + + + + org.apache.camel.springboot + camel-spring-boot-bom + ${camel.version} + pom + import + + + + + + + org.springframework.boot + spring-boot-starter + + + org.apache.camel.springboot + camel-spring-boot-starter + + + org.apache.camel.springboot + camel-observability-services-starter + + + org.apache.camel.springboot + camel-langchain4j-chat-starter + + + org.apache.camel + camel-ai-observability + + + dev.langchain4j + langchain4j-ollama-spring-boot-starter + ${langchain4j-beta-version} + + + org.springframework.boot + spring-boot-starter-actuator + + + io.micrometer + micrometer-registry-prometheus + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/spring-boot/genai-observability/prometheus.yml b/spring-boot/genai-observability/prometheus.yml new file mode 100644 index 000000000..a0a9125a1 --- /dev/null +++ b/spring-boot/genai-observability/prometheus.yml @@ -0,0 +1,16 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# + +global: + scrape_interval: 15s + +scrape_configs: + - job_name: camel-spring-boot + metrics_path: /actuator/prometheus + static_configs: + - targets: + - host.docker.internal:8080 diff --git a/spring-boot/genai-observability/src/main/java/org/apache/camel/example/genai/GenAiObservabilityApplication.java b/spring-boot/genai-observability/src/main/java/org/apache/camel/example/genai/GenAiObservabilityApplication.java new file mode 100644 index 000000000..922bf3a70 --- /dev/null +++ b/spring-boot/genai-observability/src/main/java/org/apache/camel/example/genai/GenAiObservabilityApplication.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.example.genai; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class GenAiObservabilityApplication { + + public static void main(String[] args) { + SpringApplication.run(GenAiObservabilityApplication.class, args); + } +} diff --git a/spring-boot/genai-observability/src/main/resources/application.properties b/spring-boot/genai-observability/src/main/resources/application.properties new file mode 100644 index 000000000..32d1f4266 --- /dev/null +++ b/spring-boot/genai-observability/src/main/resources/application.properties @@ -0,0 +1,29 @@ +# Spring Boot +spring.application.name=genai-observability +server.port=8080 + +# LangChain4j Ollama (auto-configures chatLanguageModel bean) +langchain4j.ollama.chat-model.base-url=http://localhost:11434 +langchain4j.ollama.chat-model.model-name=llama3.2 +langchain4j.ollama.chat-model.temperature=0.2 +langchain4j.ollama.chat-model.timeout=PT120S + +# Camel YAML routes +camel.main.routes-include-pattern=camel/* + +# GenAI observability (Camel 4.23+) +camel.ai.observability.enabled=true +camel.opentelemetry2.enabled=true + +# Actuator / Prometheus +management.endpoints.web.exposure.include=health,prometheus,info +management.endpoint.prometheus.access=read_only +management.prometheus.metrics.export.enabled=true + +# OTLP export to VictoriaTraces (docker compose stack) +camel.opentelemetry2.export-target=jaeger +otel.exporter.otlp.endpoint=http://localhost:9428/insert/opentelemetry/v1/traces +otel.exporter.otlp.protocol=http/protobuf + +# Optional: Camel CLI connector for TUI +# camel.cli.enabled=true diff --git a/spring-boot/genai-observability/src/main/resources/camel/genai-route.camel.yaml b/spring-boot/genai-observability/src/main/resources/camel/genai-route.camel.yaml new file mode 100644 index 000000000..af7a4a8ab --- /dev/null +++ b/spring-boot/genai-observability/src/main/resources/camel/genai-route.camel.yaml @@ -0,0 +1,24 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# + +- route: + id: genai-chat + from: + uri: timer:genai + parameters: + period: "15000" + steps: + - setBody: + constant: "In one sentence, what is Apache Camel integration?" + - to: + uri: langchain4j-chat:demo + parameters: + chatModel: "#chatLanguageModel" + - log: + message: "LLM reply: ${body}" + - log: + message: "Models: req=${header.CamelLangChain4jChatRequestModel} resp=${header.CamelLangChain4jChatResponseModel}" diff --git a/spring-boot/pom.xml b/spring-boot/pom.xml new file mode 100644 index 000000000..79d60bea7 --- /dev/null +++ b/spring-boot/pom.xml @@ -0,0 +1,44 @@ + + + + + 4.0.0 + + + org.apache.camel.example + camel-examples + 4.23.0-SNAPSHOT + + + camel-examples-spring-boot-parent + Camel :: Example :: Spring Boot :: Parent + Spring Boot based Camel examples + pom + + + Observability + + + + genai-observability + + +