Skip to content

feat(span-first): Better span first estimates#5936

Open
sentrivana wants to merge 2 commits intomasterfrom
ivana/span-first-estimate
Open

feat(span-first): Better span first estimates#5936
sentrivana wants to merge 2 commits intomasterfrom
ivana/span-first-estimate

Conversation

@sentrivana
Copy link
Copy Markdown
Contributor

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.

@sentrivana sentrivana requested a review from a team as a code owner April 2, 2026 08:31
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 2, 2026

Semver Impact of This PR

🟡 Minor (new features)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


This PR will not appear in the changelog.


🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 2, 2026

Codecov Results 📊

13 passed | Total: 13 | Pass Rate: 100% | Execution Time: 7.20s

📊 Comparison with Base Branch

Metric Change
Total Tests
Passed Tests
Failed Tests
Skipped Tests

✨ No test changes detected

All tests are passing successfully.

❌ Patch coverage is 0.00%. Project has 14775 uncovered lines.
✅ Project coverage is 29.96%. Comparing base (base) to head (head).

Files with missing lines (1)
File Patch % Lines
_span_batcher.py 26.51% ⚠️ 61 Missing
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       +45

Generated by Codecov Action

Copy link
Copy Markdown

@cursor cursor bot left a comment

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 prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Estimate ignores attribute key name length entirely
    • Updated _estimate_size to iterate attribute items and include key length plus a realistic per-attribute serialization overhead, eliminating the key-name underestimation gap.

Create PR

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.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant