James Netherton created CAMEL-27155:
---------------------------------------

             Summary: camel-ai-observability: Discover the implementation 
through the FactoryFinder instead of reflection
                 Key: CAMEL-27155
                 URL: https://issues.apache.org/jira/browse/CAMEL-27155
             Project: Camel
          Issue Type: Improvement
            Reporter: James Netherton
            Assignee: James Netherton


h3. Problem

{{GenAiObservability}} (camel-ai-observability-api) reaches the implementation 
in camel-ai-observability through reflection: it loads 
{{GenAiObservabilityImpl}} by class name and calls its static {{start}} method 
through {{Method.invoke}} on every LLM call.
 * Native builds such as Camel Quarkus have to register the implementation 
class for reflection.
 * The resolved state (the reflection bridge, the Micrometer {{MeterRegistry}} 
and {{ObservationRegistry}} backends) sits in static maps keyed by 
{{{}CamelContext{}}}. A stopped context, such as the one each test method 
creates, stays reachable through them.

h3. Change
 * A new {{GenAiObservationFactory}} interface in camel-ai-observability-api. 
{{GenAiObservability}} looks for one in the registry first, then through the 
{{FactoryFinder}} under 
{{{}META-INF/services/org/apache/camel/ai-observation-factory{}}}. Without 
camel-ai-observability on the classpath, calls get a no-op observation, as 
before.
 * {{GenAiObservabilityImpl}} implements the factory and is registered under 
that service key with {{{}@JdkService{}}}. Camel Quarkus core already registers 
the services under {{{}META-INF/services/org/apache/camel/*{}}}, so no 
reflection registration is needed.
 * The factory is kept as a context plugin 
({{{}ExtendedCamelContext#addContextPlugin{}}}), and it holds the Micrometer 
backends as instance fields. No static map keyed by {{CamelContext}} remains.
 * An error thrown while the observation starts, including a {{LinkageError}} 
such as a {{NoSuchMethodError}} from a Micrometer version mismatch, still 
returns a no-op observation instead of failing the LLM call.

No change to configuration or to the spans and metrics recorded.
h3. Related
 * Camel Quarkus: [https://github.com/apache/camel-quarkus/issues/9518]

_Claude Code on behalf of jamesnetherton_



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to