fix(client): Capture exceptions raised by before_send callbacks#6851
Conversation
Wrap the before_send callback invocation in capture_internal_exceptions() so that exceptions raised by user-provided before_send_log, before_send_metric, and before_send_span callbacks do not crash the application. When a callback raises, the original, unmodified telemetry item is sent. Refs PY-2617 Refs #6849
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.
Reviewed by Cursor Bugbot for commit d2f4ee7. Configure here.
| if before_send is not None: | ||
| serialized = before_send(serialized, {}) # type: ignore[arg-type] | ||
| with capture_internal_exceptions(): | ||
| serialized = before_send(serialized, {}) # type: ignore[arg-type] |
There was a problem hiding this comment.
Exception keeps telemetry instead of dropping
Medium Severity
When before_send_log or before_send_metric raises, serialized keeps its prior value and the item is still queued. That diverges from before_send and before_send_transaction in the same module, which treat a raised callback like a drop. A failing scrubbing callback can therefore still emit the original, possibly sensitive, payload.
Reviewed by Cursor Bugbot for commit d2f4ee7. Configure here.
Codecov Results 📊✅ 94273 passed | ❌ 37 failed | ⏭️ 6339 skipped | Total: 100649 | Pass Rate: 93.67% | Execution Time: 326m 19s 📊 Comparison with Base Branch
✅ Patch coverage is 100.00%. Project has 2481 uncovered lines. Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 89.68% 89.75% +0.07%
==========================================
Files 193 193 —
Lines 24007 24200 +193
Branches 8342 8494 +152
==========================================
+ Hits 21530 21719 +189
- Misses 2477 2481 +4
- Partials 1386 1381 -5Generated by Codecov Action |


Description
Issues
Reminders
uv run ruff.feat:,fix:,ref:,meta:)Stack created with GitHub Stacks CLI • Give Feedback 💬