davsclaus commented on code in PR #25337: URL: https://github.com/apache/camel/pull/25337#discussion_r3719810263
########## components/camel-ai/camel-ai-observability/pom.xml: ########## @@ -0,0 +1,69 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. + +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <artifactId>camel-ai-parent</artifactId> + <groupId>org.apache.camel</groupId> + <version>4.22.0-SNAPSHOT</version> + </parent> + + <artifactId>camel-ai-observability</artifactId> + <packaging>jar</packaging> + <name>Camel :: AI :: Observability</name> + <description>GenAI observability support for Camel AI components (OpenTelemetry and Micrometer)</description> + + <properties> + <firstVersion>4.22.0</firstVersion> + <label>ai</label> + <title>AI Observability</title> + <supportLevel>Preview</supportLevel> + </properties> + + <dependencies> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-support</artifactId> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-telemetry</artifactId> + </dependency> + <dependency> + <groupId>io.micrometer</groupId> + <artifactId>micrometer-core</artifactId> + </dependency> Review Comment: **[High]** `micrometer-core` should be marked `<optional>true</optional>`. Since `camel-ai-observability` is pulled into every AI component (langchain4j-chat, tools, agent, embeddings, openai), this forces Micrometer onto the classpath for all AI users — even those who only want OTel spans, or neither. The code in `GenAiObservability.resolveMeterRegistry()` already handles the absent case gracefully (returns null, metrics skipped). Making the dependency optional would match that design. ```suggestion <artifactId>micrometer-core</artifactId> <optional>true</optional> ``` ########## components/camel-ai/camel-ai-observability/src/main/java/org/apache/camel/component/ai/observability/GenAiModelResolver.java: ########## @@ -0,0 +1,91 @@ +/* + * 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.Method; + +/** + * Resolves GenAI provider and model metadata from LangChain4j model beans. + */ +public final class GenAiModelResolver { + + private static final String UNKNOWN = "unknown"; + + private GenAiModelResolver() { + } + + public static String resolveSystem(Object model) { + if (model == null) { + return UNKNOWN; + } + String className = model.getClass().getName().toLowerCase(); + if (className.contains("openai")) { + return "openai"; + } Review Comment: **[Medium]** The class-name substring matching is fragile. For example, a class in package `com.example.myopenai_config.SomeModel` would incorrectly match `"openai"`. Additionally, `resolveModelName` uses reflection to probe for `modelName()`, `getModelName()`, `model()` — this may break silently with langchain4j version updates. Consider using langchain4j's own `ChatResponse.modelName()` (which exists and returns the actual model name) where the response is available, rather than reflectively probing the model bean. ########## components/camel-ai/camel-langchain4j-agent-api/src/main/java/org/apache/camel/component/langchain4j/agent/api/AbstractAgent.java: ########## @@ -65,6 +66,13 @@ protected AgentConfiguration getConfiguration() { return configuration; } + /** + * Returns the LangChain4j chat model configured for this agent. + */ + public ChatModel getChatModel() { Review Comment: **[Low]** Per project conventions, new public methods in API modules should include a `@since` tag. ```suggestion public ChatModel getChatModel() { ``` Please add `@since 4.22` to the Javadoc above. ########## components/camel-ai/camel-openai/src/main/java/org/apache/camel/component/openai/OpenAIProducer.java: ########## @@ -614,11 +628,17 @@ private void processStreaming(Exchange exchange, ChatCompletionCreateParams para exchange.getUnitOfWork().addSynchronization(new Synchronization() { @Override public void onComplete(Exchange e) { + observation.recordSuccess(GenAiUsage.of(null, null, null, requestModel)); Review Comment: **[Medium]** The streaming observation records no token usage — all nulls. The OpenAI streaming API can include usage data in the final chunk when `stream_options.include_usage` is set. Recording a span with zero token information could be misleading in observability dashboards. Consider accumulating token usage from the final streaming chunk, or at minimum documenting this limitation. -- 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]
