[issue-5620] [BE] fix: handle gen_ai.usage.cost float attribute from LiteLLM OTel#5632
Open
[issue-5620] [BE] fix: handle gen_ai.usage.cost float attribute from LiteLLM OTel#5632
Conversation
…LiteLLM OTel Add COST outcome to OpenTelemetryMappingRule.Outcome and an exact-match rule for gen_ai.usage.cost placed before the gen_ai.usage.* prefix rule in GenAIMappingRules. Handle COST in OpenTelemetryMapper by extracting the DOUBLE_VALUE and storing it as totalEstimatedCost with an empty totalEstimatedCostVersion sentinel (marking it as manually set). Previously gen_ai.usage.cost was silently dropped because the USAGE outcome only handles INT_VALUE and STRING_VALUE, not DOUBLE_VALUE. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Contributor
Contributor
Contributor
Contributor
Contributor
Contributor
Contributor
Contributor
Contributor
Contributor
Contributor
Contributor
Contributor
Contributor
Contributor
Contributor
Contributor
Contributor
Contributor
Contributor
andrescrz
reviewed
Mar 13, 2026
|
|
||
| case COST : | ||
| spanBuilder.totalEstimatedCost(BigDecimal.valueOf(value.getDoubleValue())); | ||
| spanBuilder.totalEstimatedCostVersion(""); |
Member
There was a problem hiding this comment.
Why do you need to set this to the empty string? By default it's null, I believe it should be handled.
| break; | ||
|
|
||
| case COST : | ||
| spanBuilder.totalEstimatedCost(BigDecimal.valueOf(value.getDoubleValue())); |
Member
There was a problem hiding this comment.
For more precision in the conversion, it's better to attempt to instantiate the BigDecimal from the JSON string value.
| } | ||
|
|
||
| @Test | ||
| void testGenAiUsageCostNotAddedToUsageMap() { |
Member
There was a problem hiding this comment.
Please merge similar tests. It seems only the assertion diverges.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Details
Add COST outcome to OpenTelemetryMappingRule.Outcome and an exact-match rule for gen_ai.usage.cost placed before the gen_ai.usage.* prefix rule in GenAIMappingRules. Handle COST in OpenTelemetryMapper by extracting the DOUBLE_VALUE and storing it as totalEstimatedCost with an empty totalEstimatedCostVersion sentinel (marking it as manually set).
Previously gen_ai.usage.cost was silently dropped because the USAGE outcome only handles INT_VALUE and STRING_VALUE, not DOUBLE_VALUE.
Change checklist
Issues
Testing
Tests added.
Documentation
N/A