Skip to content

feat(anthropic): Set gen_ai.usage.output_tokens.reasoning attributes for non-streaming responses - #8329

Merged
srothh merged 6 commits into
masterfrom
srothh/anthropic-output-tokens-reasoning-attributes
Nov 19, 2026
Merged

srothh merged 6 commits into
masterfrom
srothh/anthropic-output-tokens-reasoning-attributes

Conversation

@srothh

@srothh srothh commented Nov 18, 2026

Copy link
Copy Markdown
Contributor

Description

Count the number of reasoning tokens in non-streaming anthropic responses in the anthropic integration.

Issues

resolves: #5802
resolves: PY-2208

@linear-code

linear-code Bot commented Nov 18, 2026

Copy link
Copy Markdown

PY-2208

@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Coverage Results 📊

✅ 139495 passed | ⏭️ 7905 skipped | Total: 147400 | Pass Rate: 94.64% | Execution Time: 834m 20s

📊 Comparison with Base Branch

Metric Change
Total Tests 📈 +239
Passed Tests 📈 +192
Failed Tests 📉 -1
Skipped Tests 📈 +48

All tests are passing successfully.

✅ Patch coverage is 94.12% (16 of 17 changed executable lines covered; target 80%).
Project statement coverage is 90.22% (unchanged from base (4b701c0) to head (cf28b45)).

Changed files with executable lines (1)
File Patch coverage Changed executable lines
sentry_sdk/integrations/anthropic.py 94.12% 16/17 covered; missed: 434; partial branches: 433
Coverage diff
@@            Coverage Diff             @@
##        master     #8329       +/-##
==========================================
  Coverage    90.22%    90.22%        —%
==========================================
  Files          203       203         —
  Tracked lines     27333     27349       +16
  Branches     10242     10252       +10
==========================================
+ Hits         24660     24675       +15
- Misses        2673      2674        +1
- Partials      1556      1557        +1

Generated by Coverage Action

@srothh
srothh marked this pull request as ready for review November 18, 2026 14:37
@srothh
srothh requested a review from a team as a code owner November 18, 2026 14:37
…for streaming responses (#8330)

### Description
feat(anthropic): Set gen_ai.usage.output_tokens.reasoning attributes for
streaming responses

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want fixes drafted automatically? Bugbot Autofix can create code changes for findings. A team admin can enable Autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit cf28b45. Configure here.

if hasattr(usage, "output_tokens_details"):
reasoning = getattr(usage.output_tokens_details, "thinking_tokens", None)
if isinstance(reasoning, int):
output_tokens_reasoning = reasoning

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Absent reasoning tokens recorded as zero

Medium Severity

_get_token_usage and _RecordedUsage default missing reasoning tokens to 0 rather than None. _set_output_data only omits gen_ai.usage.output_tokens.reasoning when the value is None, so every Anthropic span records 0 when thinking_tokens is absent, including older SDKs that used thinking but did not report a breakdown.

Additional Locations (2)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit cf28b45. Configure here.

@srothh
srothh merged commit 7499ae7 into master Nov 19, 2026
351 of 353 checks passed
@srothh
srothh deleted the srothh/anthropic-output-tokens-reasoning-attributes branch November 19, 2026 09:44
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.

anthropic: Set gen_ai.usage.output_tokens.reasoning attributes

2 participants