Omar Atie created CAMEL-24560:
---------------------------------

             Summary: Change GenAiUsage token fields from Integer to Long
                 Key: CAMEL-24560
                 URL: https://issues.apache.org/jira/browse/CAMEL-24560
             Project: Camel
          Issue Type: New Feature
            Reporter: Omar Atie


h2. Background

During PR #25337 review, Claus Ibsen noted that OpenAI token counts 
(usage.promptTokens(), usage.completionTokens()) return long, but GenAiUsage 
stores Integer inputTokens/outputTokens, requiring lossy (int) casts in 
OpenAIProducer.

h2. Problem

Large token counts could overflow Integer.MAX_VALUE. Casting long to int is a 
silent data-loss risk for observability dashboards and metrics.

h2. Proposed scope

* Change GenAiUsage record fields inputTokens and outputTokens from Integer to 
Long
* Update all call sites (OpenAIProducer, LangChain4j producers, 
SpringAiChatProducer, GenAiObservabilityImpl, Micrometer backend)
* Update GenAiUsage.of() factory
* Update tests and span attribute serialization
* Add upgrade-guide note if any public API/header behavior changes (unlikely 
for internal record, but document if metrics tags change type)

h2. References

* Parent: CAMEL-23861
* components/camel-ai/camel-ai-observability-api/.../GenAiUsage.java
* apache/camel PR #25337 review (davsclaus)

h2. Acceptance criteria

* No (int) casts on OpenAI token usage
* All existing observability tests pass
* Span attributes and Micrometer metrics accept long token values correctly
* API change documented if camel-ai-observability-api is considered public SPI



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to