Repository navigation
feat: Add basic lock-free metrics batcher - #8326
alexander-alderman-webb wants to merge 26 commits into
Conversation
Coverage Results 📊✅ 59448 passed | ❌ 1 failed | ⏭️ 3118 skipped | Total: 62567 | Pass Rate: 95.01% | Execution Time: 161m 59s 📊 Comparison with Base Branch
➕ New Tests (1)View new tests
❌ Failed Tests
|
| File | Patch coverage | Changed executable lines |
|---|---|---|
| sentry_sdk/_lock_free_metrics_batcher.py | 0.00% | 0/81 covered; missed: 1, 2, 3, 4, 5, 7, 8, 9, 20, 21, 22, 23, 25, 26, 27, 29, 34, 35, 37, 39, 40, 41, 42, 44, 48, 49, 51, 52, 53, 56, 57, 58, 60, 62, 63, 65, 66, 67, 70, 71, 73, 75, 77, 78, 80, 81, 82, 83, 85, 86, 87, 88, 90, 91, 92, 94, 96, 98, 99, 100, 102, 103, 104, 105, 106, 108, 109, 111, 114, 115, 116, 118, 119, 120, 130, 131, 133, 134, 136, 137, 139 |
Coverage diff
@@ Coverage Diff @@
## master #8326 +/-##
==========================================
- Coverage 90.12% 89.81% -0.31%
==========================================
Files 201 202 +1
Tracked lines 22199 22345 +146
Branches 7784 7820 +36
==========================================
+ Hits 20004 20067 +63
- Misses 2195 2278 +83
- Partials 1283 1289 +6Generated by Coverage Action
…ndow-metrics-batcher
…ndow-metrics-batcher
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
| # dict.setdefault is atomic, so exactly one thread gets to start the flusher. | ||
| claim = object() | ||
| if self._flusher_claim.setdefault("flusher", claim) is not claim: |
There was a problem hiding this comment.
TIL of this setdefault hack
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 99641dc. Configure here.
PR risk: mediumFor commit Main concerns: data sent to Sentry, host performance, reach. This label is a hint for reviewers, not an approval. |

Description
Add a lock-free metrics batcher using a
collections.dequeat the core.Consumers pop from the front of the queue, and producers add to the end of the queue.
The main trade-off is that limits are not precise anymore. The
MAX_BEFORE_FLUSHlimit can now be exceeded by one or more metrics per thread (conceptually, imagine all threads adding their metric simultaneously as the worst case).There can be two consumers if
sentry_sdk.flush()is called concurrently with a flush induced by reaching a limit. Consumers therefore handleIndexError.Issues
Reminders
uv run ruff.feat:,fix:,ref:,meta:)