atiaomar1978-hub commented on code in PR #25337:
URL: https://github.com/apache/camel/pull/25337#discussion_r3724512182


##########
components/camel-ai/camel-langchain4j-chat/pom.xml:
##########
@@ -63,10 +63,21 @@
             <version>${jackson2-version}</version>
         </dependency>
 
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-ai-observability</artifactId>

Review Comment:
   _AI-generated on behalf of atiaomar1978-hub._
   
   Addressed in 38821e3: introduced `camel-ai-observability-api` (lightweight 
types + reflection bridge). AI producers now depend only on the API module; 
`camel-ai-observability` (with `camel-telemetry`) is opt-in for users who want 
spans/metrics. Same pattern as PQC/Micrometer.



##########
docs/components/modules/others/nav.adoc:
##########
@@ -4,6 +4,7 @@
 * xref:others:index.adoc[Miscellaneous Components]
 ** xref:a2a-consumer.adoc[A2A - Consumer Guide]
 ** xref:a2a-producer.adoc[A2A - Producer Guide]
+*** xref:ai-observability.adoc[AI Observability]

Review Comment:
   _AI-generated on behalf of atiaomar1978-hub._
   
   Fixed: removed `:group: AI` from `ai-observability.adoc` and regenerated 
`docs/components/modules/others/nav.adoc` via `prepare-doc-symlinks`. AI 
Observability is now a top-level `**` entry under Miscellaneous Components, not 
nested under A2A.



##########
components/camel-ai/camel-ai-observability/src/main/java/org/apache/camel/component/ai/observability/GenAiObservability.java:
##########
@@ -0,0 +1,216 @@
+/*
+ * 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.component.ai.observability;
+
+import java.lang.reflect.Constructor;
+import java.util.Optional;
+
+import org.apache.camel.CamelContext;
+import org.apache.camel.Exchange;
+import org.apache.camel.telemetry.Span;
+import org.apache.camel.telemetry.SpanLifecycleManager;
+import org.apache.camel.telemetry.SpanStorageManagerExchange;
+import org.apache.camel.telemetry.Tracer;
+import 
org.apache.camel.telemetry.propagation.CamelHeadersSpanContextPropagationExtractor;
+import org.apache.camel.util.ObjectHelper;
+
+/**
+ * Entry point for GenAI observability in Camel AI producers.
+ */
+public final class GenAiObservability {
+
+    private static final String CLIENT_SPAN_KIND = "CLIENT";
+    private static final String METER_REGISTRY_CLASS = 
"io.micrometer.core.instrument.MeterRegistry";
+    private static final String MICROMETER_SUPPORT_CLASS
+            = 
"org.apache.camel.component.ai.observability.GenAiMicrometerSupport";
+    private static final GenAiObservation NOOP = new NoopGenAiObservation();
+
+    private GenAiObservability() {
+    }
+
+    /**
+     * Whether GenAI observability is enabled for the given context.
+     */
+    public static boolean isEnabled(CamelContext camelContext) {
+        if (camelContext == null) {
+            return false;
+        }
+        Optional<String> property
+                = 
camelContext.getPropertiesComponent().resolveProperty(GenAiObservabilityProperties.ENABLED);
+        if (property.isPresent()) {
+            return Boolean.parseBoolean(property.get().trim());
+        }
+        return true;
+    }
+
+    /**
+     * Starts a GenAI observation for a single LLM client call. Returns a 
no-op when disabled or no backend is
+     * available.
+     */
+    public static GenAiObservation start(Exchange exchange, 
GenAiObservationContext context) {
+        if (exchange == null || context == null || 
!isEnabled(exchange.getContext())) {
+            return NOOP;
+        }
+        Tracer tracer = exchange.getContext().hasService(Tracer.class);
+        GenAiMetricsBackend metricsBackend = 
resolveMetricsBackend(exchange.getContext());
+        if (tracer == null && (metricsBackend == null || 
!metricsBackend.isAvailable())) {
+            return NOOP;
+        }
+        return new DefaultGenAiObservation(exchange, context, tracer, 
metricsBackend);
+    }
+
+    private static GenAiMetricsBackend resolveMetricsBackend(CamelContext 
camelContext) {
+        try {
+            Class.forName(METER_REGISTRY_CLASS);
+            Class<?> supportClass = Class.forName(MICROMETER_SUPPORT_CLASS);
+            Constructor<?> constructor = 
supportClass.getDeclaredConstructor(CamelContext.class);
+            constructor.setAccessible(true);

Review Comment:
   _AI-generated on behalf of atiaomar1978-hub._
   
   Fixed: removed `setAccessible(true)` in `GenAiObservabilityImpl` — 
`GenAiMicrometerSupport` is package-private and accessible without reflection 
tricks.



##########
catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/jbang/camel-jbang-configuration-metadata.json:
##########
@@ -35,6 +35,7 @@
     { "name": "camel.jbang.maven-settings", "required": false, "description": 
"Optional location of Maven settings.xml file to configure servers, 
repositories, mirrors, and proxies. If set to false, not even the default 
\/.m2\/settings.xml will be used.", "label": "maven", "type": "string", 
"javaType": "String", "secret": false },
     { "name": "camel.jbang.maven-settings-security", "required": false, 
"description": "Optional location of Maven settings-security.xml file to 
decrypt Maven Settings (settings.xml) file", "label": "maven", "type": 
"string", "javaType": "String", "secret": false },
     { "name": "camel.jbang.mavenWrapper", "required": false, "description": 
"Include Maven Wrapper files in the exported project", "type": "boolean", 
"javaType": "boolean", "defaultValue": true, "secret": false },
+    { "name": "camel.jbang.mcp", "required": false, "description": "Embed 
dev\/diagnostics MCP tools on the local HTTP management server (\/mcp by 
default)", "type": "boolean", "javaType": "boolean", "defaultValue": false, 
"secret": false, "security": "insecure:dev" },

Review Comment:
   _AI-generated on behalf of atiaomar1978-hub._
   
   Confirmed removed: `camel.jbang.mcp` is not present in the regenerated 
catalog on this branch (was cleaned up in e870186 and verified again after 
rebuild).



##########
components/camel-ai/camel-langchain4j-chat/pom.xml:
##########
@@ -63,10 +63,21 @@
             <version>${jackson2-version}</version>
         </dependency>
 
+        <dependency>
+            <groupId>org.apache.camel</groupId>
+            <artifactId>camel-ai-observability</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+
         <!-- for testing -->
         <dependency>
             <groupId>org.apache.camel</groupId>
-            <artifactId>camel-test-spring-junit6</artifactId>
+            <artifactId>camel-test-junit6</artifactId>

Review Comment:
   _AI-generated on behalf of atiaomar1978-hub._
   
   Restored `camel-test-spring-junit6` and kept `camel-test-junit6` as an 
additional test dependency (observability tests use `CamelTestSupport`). No 
replacement of the original dependency.
   
   Also added producer-level observability tests for `langchain4j-tools`, 
`langchain4j-embeddings`, and `openai`.



-- 
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]

Reply via email to