Repository navigation
feat(anthropic): Set gen_ai.usage.output_tokens.reasoning attributes for non-streaming responses - #8329
Conversation
kens.reasoning for non-streaming responses #5802
Coverage Results 📊✅ 139495 passed | ⏭️ 7905 skipped | Total: 147400 | Pass Rate: 94.64% | Execution Time: 834m 20s 📊 Comparison with Base Branch
All tests are passing successfully. ✅ Patch coverage is 94.12% (16 of 17 changed executable lines covered; target 80%). Changed files with executable lines (1)
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 +1Generated by Coverage Action |
…for streaming responses (#8330) ### Description feat(anthropic): Set gen_ai.usage.output_tokens.reasoning attributes for streaming responses
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ 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 |
There was a problem hiding this comment.
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)
Reviewed by Cursor Bugbot for commit cf28b45. Configure here.


Description
Count the number of reasoning tokens in non-streaming anthropic responses in the anthropic integration.
Issues
resolves: #5802
resolves: PY-2208