atiaomar1978-hub opened a new pull request, #25337: URL: https://github.com/apache/camel/pull/25337
# Description Implements **Phase 1** of [CAMEL-23861](https://issues.apache.org/jira/browse/CAMEL-23861) — GenAI observability for Camel AI route producers, aligned with Claus Ibsen's latest JIRA guidance: - **Ad 1:** langchain4j + openai components - **Ad 2:** model identification headers on langchain4j producers - **Ad 3:** global on/off toggle via `camel.ai.observability.enabled` - **Ad 4:** OpenTelemetry spans first, then Micrometer metrics _AI-generated PR description on behalf of atiaomar1978-hub_ ## What changed ### New module: `camel-ai-observability` Shared library providing GenAI observability for Camel AI producers: - **OpenTelemetry:** child span per LLM call via `camel-telemetry.Tracer` + GenAI semantic convention attributes (`gen_ai.operation.name`, `gen_ai.system`, `gen_ai.request.model`, token usage, etc.) - **Micrometer:** `gen_ai.client.operation` timer and `gen_ai.client.token.usage` counter (Spring AI–aligned metric names) - **Global toggle:** `camel.ai.observability.enabled` (default `true`; no-op when disabled or no backend present) - **Tracer resolution:** uses `CamelContext.hasService(Tracer.class)` so `camel-opentelemetry2` service registration is discovered correctly - **Span kind:** `CLIENT` with exchange header propagation extractor for parent trace linking ### Producer integrations (Phase 1) | Component | Integration | |-----------|-------------| | `langchain4j-chat` | Wraps each `chatModel.chat()` call | | `langchain4j-tools` | Per tool-calling LLM iteration in `chatWithLLM()` | | `langchain4j-agent` | Per agent invocation (chat model resolved from agent configuration) | | `langchain4j-embeddings` | Per embedding call | | `openai` | `createChatCompletion()` and streaming path | ### New exchange headers (langchain4j) - `CamelLangChain4jChatRequestModel` / `CamelLangChain4jChatResponseModel` - `CamelLangChain4jToolsRequestModel` / `CamelLangChain4jToolsResponseModel` - `CamelLangChain4jAgentRequestModel` / `CamelLangChain4jAgentResponseModel` - `CamelLangChain4jEmbeddingsRequestModel` / `CamelLangChain4jEmbeddingsResponseModel` OpenAI already exposes `MODEL` / `RESPONSE_MODEL`. ### Documentation - Component doc: `components/camel-ai/camel-ai-observability/src/main/docs/ai-observability.adoc` - Upgrade guide entry in `docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_22.adoc` ## Design notes - **Child span per LLM call** (not route-span enrichment only) — required for multi-iteration tool-calling loops - Stable GenAI semconv subset aligned with Spring AI - Micrometer uses direct `MeterRegistry` binding; Micrometer Observation API deferred to follow-up - Phase 2 (separate scope): `camel ask` / TUI observability per Claus comment ## Tests - `GenAiModelResolverTest` — provider/model resolution - `GenAiObservabilityTest` — global toggle, Micrometer metrics - `GenAiObservabilitySpanTest` — OTel span attributes and error tagging - `GenAiObservationContextTest` — span naming convention ```bash mvn test -pl components/camel-ai/camel-ai-observability -am -DskipITs ``` ## Target - [x] Commit targets `main` (Camel 4.22.0-SNAPSHOT) ## Tracking - [x] [CAMEL-23861](https://issues.apache.org/jira/browse/CAMEL-23861) ## AI-assisted contributions - [x] AI-assisted (Cursor Cloud Agent) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
