Skip to content

[issue-5620] [BE] fix: handle gen_ai.usage.cost float attribute from LiteLLM OTel#5632

Open
dsblank wants to merge 1 commit intomainfrom
ollie/issue-5620-handle-float-cost-attribute-242874
Open

[issue-5620] [BE] fix: handle gen_ai.usage.cost float attribute from LiteLLM OTel#5632
dsblank wants to merge 1 commit intomainfrom
ollie/issue-5620-handle-float-cost-attribute-242874

Conversation

@dsblank
Copy link
Copy Markdown
Contributor

@dsblank dsblank commented Mar 11, 2026

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

  • User facing
  • Documentation update

Issues

Testing

Tests added.

Documentation

N/A

…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>
@github-actions github-actions bot added java Pull requests that update Java code Backend tests Including test files, or tests related like configuration. labels Mar 11, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Backend Tests - Unit Tests

1 315 tests  +3   1 313 ✅ +3   52s ⏱️ -3s
  161 suites ±0       2 💤 ±0 
  161 files   ±0       0 ❌ ±0 

Results for commit be8a447. ± Comparison against base commit dc3393b.

@github-actions
Copy link
Copy Markdown
Contributor

Backend Tests - Integration Group 5

109 tests  ±0   109 ✅ ±0   2m 19s ⏱️ +3s
 22 suites ±0     0 💤 ±0 
 22 files   ±0     0 ❌ ±0 

Results for commit be8a447. ± Comparison against base commit dc3393b.

@github-actions
Copy link
Copy Markdown
Contributor

Backend Tests - Integration Group 11

158 tests  ±0   155 ✅ ±0   2m 20s ⏱️ -9s
 22 suites ±0     3 💤 ±0 
 22 files   ±0     0 ❌ ±0 

Results for commit be8a447. ± Comparison against base commit dc3393b.

@github-actions
Copy link
Copy Markdown
Contributor

Backend Tests - Integration Group 15

195 tests  ±0   195 ✅ ±0   3m 4s ⏱️ +7s
 31 suites ±0     0 💤 ±0 
 31 files   ±0     0 ❌ ±0 

Results for commit be8a447. ± Comparison against base commit dc3393b.

@github-actions
Copy link
Copy Markdown
Contributor

Backend Tests - Integration Group 7

 24 files  ±0   24 suites  ±0   2m 6s ⏱️ -13s
234 tests ±0  234 ✅ ±0  0 💤 ±0  0 ❌ ±0 
232 runs   - 2  232 ✅  - 2  0 💤 ±0  0 ❌ ±0 

Results for commit be8a447. ± Comparison against base commit dc3393b.

@github-actions
Copy link
Copy Markdown
Contributor

Backend Tests - Integration Group 16

 23 files  ±0   23 suites  ±0   2m 36s ⏱️ +6s
139 tests ±0  139 ✅ ±0  0 💤 ±0  0 ❌ ±0 
118 runs  +1  118 ✅ +1  0 💤 ±0  0 ❌ ±0 

Results for commit be8a447. ± Comparison against base commit dc3393b.

@github-actions
Copy link
Copy Markdown
Contributor

Backend Tests - Integration Group 14

195 tests  ±0   195 ✅ ±0   2m 36s ⏱️ +6s
 20 suites ±0     0 💤 ±0 
 20 files   ±0     0 ❌ ±0 

Results for commit be8a447. ± Comparison against base commit dc3393b.

@github-actions
Copy link
Copy Markdown
Contributor

Backend Tests - Integration Group 6

1 136 tests  ±0   1 136 ✅ ±0   5m 16s ⏱️ -17s
    5 suites ±0       0 💤 ±0 
    5 files   ±0       0 ❌ ±0 

Results for commit be8a447. ± Comparison against base commit dc3393b.

@github-actions
Copy link
Copy Markdown
Contributor

Backend Tests - Integration Group 12

173 tests  ±0   173 ✅ ±0   5m 36s ⏱️ +8s
 35 suites ±0     0 💤 ±0 
 35 files   ±0     0 ❌ ±0 

Results for commit be8a447. ± Comparison against base commit dc3393b.

@github-actions
Copy link
Copy Markdown
Contributor

Backend Tests - Integration Group 10

231 tests  ±0   229 ✅ ±0   6m 49s ⏱️ -23s
 18 suites ±0     2 💤 ±0 
 18 files   ±0     0 ❌ ±0 

Results for commit be8a447. ± Comparison against base commit dc3393b.

@github-actions
Copy link
Copy Markdown
Contributor

Backend Tests - Integration Group 8

271 tests  ±0   271 ✅ ±0   4m 7s ⏱️ +10s
 19 suites ±0     0 💤 ±0 
 19 files   ±0     0 ❌ ±0 

Results for commit be8a447. ± Comparison against base commit dc3393b.

@github-actions
Copy link
Copy Markdown
Contributor

Backend Tests - Integration Group 1

 21 files  ± 0   21 suites  ±0   8m 8s ⏱️ + 5m 52s
391 tests ± 0  391 ✅ ± 0  0 💤 ±0  0 ❌ ±0 
391 runs  +72  391 ✅ +72  0 💤 ±0  0 ❌ ±0 

Results for commit be8a447. ± Comparison against base commit dc3393b.

@github-actions
Copy link
Copy Markdown
Contributor

Backend Tests - Integration Group 9

336 tests  ±0   330 ✅ ±0   8m 13s ⏱️ +6s
 35 suites ±0     6 💤 ±0 
 35 files   ±0     0 ❌ ±0 

Results for commit be8a447. ± Comparison against base commit dc3393b.

@github-actions
Copy link
Copy Markdown
Contributor

Backend Tests - Integration Group 4

    5 files  ±0      5 suites  ±0   3m 3s ⏱️ -2s
1 361 tests ±0  1 361 ✅ ±0  0 💤 ±0  0 ❌ ±0 
1 272 runs  ±0  1 272 ✅ ±0  0 💤 ±0  0 ❌ ±0 

Results for commit be8a447. ± Comparison against base commit dc3393b.

@github-actions
Copy link
Copy Markdown
Contributor

Backend Tests - Integration Group 3

307 tests  ±0   307 ✅ ±0   10m 3s ⏱️ -33s
 28 suites ±0     0 💤 ±0 
 28 files   ±0     0 ❌ ±0 

Results for commit be8a447. ± Comparison against base commit dc3393b.

@github-actions
Copy link
Copy Markdown
Contributor

Backend Tests - Integration Group 13

417 tests  ±0   417 ✅ ±0   8m 29s ⏱️ +11s
 11 suites ±0     0 💤 ±0 
 11 files   ±0     0 ❌ ±0 

Results for commit be8a447. ± Comparison against base commit dc3393b.

@github-actions
Copy link
Copy Markdown
Contributor

Backend Tests - Integration Group 2

256 tests  ±0   256 ✅ ±0   18m 19s ⏱️ +24s
 19 suites ±0     0 💤 ±0 
 19 files   ±0     0 ❌ ±0 

Results for commit be8a447. ± Comparison against base commit dc3393b.

@github-actions
Copy link
Copy Markdown
Contributor

TS SDK E2E Tests - Node 20

236 tests  ±0   234 ✅ ±0   17m 53s ⏱️ - 8m 9s
 25 suites ±0     2 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit be8a447. ± Comparison against base commit dc3393b.

@github-actions
Copy link
Copy Markdown
Contributor

TS SDK E2E Tests - Node 18

236 tests  ±0   234 ✅ ±0   17m 20s ⏱️ - 11m 10s
 25 suites ±0     2 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit be8a447. ± Comparison against base commit dc3393b.

@github-actions
Copy link
Copy Markdown
Contributor

TS SDK E2E Tests - Node 22

236 tests  ±0   234 ✅ ±0   18m 41s ⏱️ - 8m 27s
 25 suites ±0     2 💤 ±0 
  1 files   ±0     0 ❌ ±0 

Results for commit be8a447. ± Comparison against base commit dc3393b.

@dsblank dsblank marked this pull request as ready for review March 12, 2026 18:13
@dsblank dsblank requested a review from a team as a code owner March 12, 2026 18:13

case COST :
spanBuilder.totalEstimatedCost(BigDecimal.valueOf(value.getDoubleValue()));
spanBuilder.totalEstimatedCostVersion("");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()));
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For more precision in the conversion, it's better to attempt to instantiate the BigDecimal from the JSON string value.

}

@Test
void testGenAiUsageCostNotAddedToUsageMap() {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please merge similar tests. It seems only the assertion diverges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backend java Pull requests that update Java code tests Including test files, or tests related like configuration.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] LiteLLM OTel: gen_ai.usage.cost (pre-computed cost) is silently dropped and ignored

2 participants