feat(span-first): Better span first estimates#5936
feat(span-first): Better span first estimates#5936sentrivana wants to merge 2 commits intomasterfrom
Conversation
Semver Impact of This PR🟡 Minor (new features) 📋 Changelog PreviewThis is how your changes will appear in the changelog. This PR will not appear in the changelog. 🤖 This preview updates automatically when you update the PR. |
Codecov Results 📊✅ 13 passed | Total: 13 | Pass Rate: 100% | Execution Time: 7.20s 📊 Comparison with Base Branch
✨ No test changes detected All tests are passing successfully. ❌ Patch coverage is 0.00%. Project has 14775 uncovered lines. Files with missing lines (1)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 25.16% 29.96% +4.8%
==========================================
Files 190 190 —
Lines 21088 21094 +6
Branches 6884 6888 +4
==========================================
+ Hits 5306 6319 +1013
- Misses 15782 14775 -1007
- Partials 432 477 +45Generated by Codecov Action |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix prepared a fix for the issue found in the latest run.
- ✅ Fixed: Estimate ignores attribute key name length entirely
- Updated
_estimate_sizeto iterate attribute items and include key length plus a realistic per-attribute serialization overhead, eliminating the key-name underestimation gap.
- Updated
Or push these changes by commenting:
@cursor push 829ce915e2
Preview (829ce915e2)
diff --git a/sentry_sdk/_span_batcher.py b/sentry_sdk/_span_batcher.py
--- a/sentry_sdk/_span_batcher.py
+++ b/sentry_sdk/_span_batcher.py
@@ -94,8 +94,8 @@
# 210 is the rough size of the payload without attributes, and then we
# estimate the attributes separately.
estimate = 210
- for value in item._attributes.values():
- estimate += 7
+ for key, value in item._attributes.items():
+ estimate += 40 + len(key)
if isinstance(value, str):
estimate += len(value)This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.


We were underestimating the size of spans with particularly bulky attributes, and flushing the buffer too late as a result. Take attribute size into account for estimating.