[
https://issues.apache.org/jira/browse/CAMEL-23861?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18092931#comment-18092931
]
Claus Ibsen commented on CAMEL-23861:
-------------------------------------
h3. Spring AI Reference Implementation
Spring AI already implements GenAI observability through the Micrometer
Observation API following the [OpenTelemetry Semantic Conventions for
GenAI|https://opentelemetry.io/docs/specs/semconv/gen-ai/]. Here is where the
key code lives in
[spring-projects/spring-ai|https://github.com/spring-projects/spring-ai] for
reference:
*Convention constants* — {{spring-ai-commons/.../observation/conventions/}}
* {{AiProvider.java}} — enum of providers (openai, anthropic, google, etc.)
* {{AiObservationMetricNames.java}} — metric name constants
* {{AiTokenType.java}} — token type classification
*Chat model observation* — {{spring-ai-model/.../chat/observation/}}
* {{DefaultChatModelObservationConvention.java}} — main convention impl
defining all span attributes
* {{ChatModelObservationContext.java}} — context object carrying
request/response data
* {{ChatModelMeterObservationHandler.java}} — Micrometer metrics handler
* {{ChatModelCompletionObservationHandler.java}} — completion observations
*OpenTelemetry GenAI span attributes implemented:*
||Attribute||Description||
|gen_ai.operation.name|e.g. "chat"|
|gen_ai.system|provider (openai, anthropic)|
|gen_ai.request.model / gen_ai.response.model|model names|
|gen_ai.usage.input_tokens / gen_ai.usage.output_tokens|token counts|
|gen_ai.response.finish_reasons|completion reasons|
|gen_ai.request.temperature, top_k, top_p, max_tokens|request params|
*Metrics:*
* {{gen_ai.client.operation.duration}} — histogram (seconds)
* {{gen_ai.client.token.usage}} — histogram (tokens)
*References:*
* GitHub issue tracking Spring AI observability:
[spring-ai#1174|https://github.com/spring-projects/spring-ai/issues/1174]
* Spring AI observability docs:
[https://docs.spring.io/spring-ai/reference/observability/index.html]
* OTel GenAI semantic conventions spec:
[https://opentelemetry.io/docs/specs/semconv/gen-ai/]
The pattern is: each ChatModel creates a {{ChatModelObservationContext}},
starts an observation via Micrometer's {{ObservationRegistry}}, and the
convention/handlers automatically extract the span attributes and metrics.
Spans are named {{\{operation\} \{model\}}} (e.g. "chat gpt-4o") with kind
INTERNAL.
> camel-langchain4j - Add OpenTelemetry and Micrometer observability for AI/LLM
> usage
> -----------------------------------------------------------------------------------
>
> Key: CAMEL-23861
> URL: https://issues.apache.org/jira/browse/CAMEL-23861
> Project: Camel
> Issue Type: Improvement
> Components: camel-langchain4j-agent, camel-langchain4j-chat,
> camel-langchain4j-embeddings, camel-langchain4j-tools
> Reporter: Claus Ibsen
> Priority: Major
> Labels: ai, observability
> Fix For: 4.22.0
>
>
> The camel-langchain4j components currently have no observability integration
> for AI/LLM-specific metrics and tracing. Token usage, model name, finish
> reason, and latency are not captured.
> Spring AI exposes this data through the Micrometer Observation API (which
> produces both metrics and traces) following the OpenTelemetry Semantic
> Conventions for GenAI (https://opentelemetry.io/docs/specs/semconv/gen-ai/).
> This enables dashboards showing token consumption, costs, model distribution,
> and conversation tracking.
> Camel should follow the same approach. When camel-micrometer or
> camel-opentelemetry2 is active, the langchain4j producers should capture:
> *OpenTelemetry span attributes (GenAI semantic conventions):*
> - gen_ai.system (e.g. openai, anthropic)
> - gen_ai.request.model
> - gen_ai.response.model
> - gen_ai.usage.input_tokens
> - gen_ai.usage.output_tokens
> - gen_ai.response.finish_reasons
> *Micrometer metrics:*
> - Token counters (input/output/total) with model tag
> - Request counters per model/operation
> - Latency timers/histograms
> - Error counters
> This would allow standard observability tooling (Grafana, Jaeger, Prometheus,
> etc.) and Camel TUI to visualize AI/LLM usage across routes.
> See also CAMEL-23860 which adds token data as exchange headers - this ticket
> is about propagating that data into the observability layer for monitoring
> and dashboards.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)