Skip to content

feat(litellm): record final response cost - #8044

Draft
sehr-m wants to merge 1 commit into
masterfrom
feat/litellm-response-cost
Draft

sehr-m wants to merge 1 commit into
masterfrom
feat/litellm-response-cost

Conversation

@sehr-m

@sehr-m sehr-m commented Oct 15, 2026 •

Copy link
Copy Markdown
Member

Summary

  • record LiteLLM's final response cost on GenAI spans
  • prefer the top-level response_cost value so a supported LiteLLM logging hook can replace the calculated cost before observability callbacks run
  • fall back to the standard logging payload for compatibility

This lets applications correct a provider-specific pricing gap without reaching into Sentry's private span state. The consuming getsentry/ops#24340 change uses a LiteLLM CustomLogger logging hook to overwrite response_cost before this integration finishes the span.

Validation

  • focused LiteLLM integration test passes in all four static/streaming span configurations on LiteLLM 1.96.0
  • Ruff lint and formatting pass
  • mypy passes for the full SDK

@github-actions

Copy link
Copy Markdown
Contributor

Coverage Results 📊

✅ 133666 passed | ⏭️ 7276 skipped | Total: 140942 | Pass Rate: 94.84% | Execution Time: 446m 12s

📊 Comparison with Base Branch

Metric Change
Total Tests —
Passed Tests —
Failed Tests —
Skipped Tests —

✨ Test counts unchanged from base.

All tests are passing successfully.

✅ Patch coverage is 100.00% (10 of 10 changed executable lines covered; target 80%).
Project statement coverage is 90.23% (unchanged from base (ab069a5) to head (c97eef5)).

Changed files with executable lines (2)
File Patch coverage Changed executable lines
sentry_sdk/consts.py 100.00% 2/2 covered
sentry_sdk/integrations/litellm.py 100.00% 8/8 covered
Coverage diff
@@            Coverage Diff             @@
##        master     #8044       +/-##
==========================================
  Coverage    90.23%    90.23%        —%
==========================================
  Files          202       202         —
  Tracked lines     26660     26669        +9
  Branches      9926      9932        +6
==========================================
+ Hits         24055     24063        +8
- Misses        2605      2606        +1
- Partials      1510      1511        +1

Generated by Coverage Action

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant