feat: Add `beforeBreadcrumb` callback support by tustanivsky · Pull Request #1534 · getsentry/sentry-native
Summary
This PR adds beforeBreadcrumb callback support allowing users to inspect, modify or discard breadcrumbs before they are added to global scope. The callback fires in sentry_add_breadcrumb (global path only); breadcrumbs added directly to local scopes via sentry_scope_add_breadcrumb bypass it. When a breadcrumb is discarded, neither the backend nor the scope is notified (no ghost breadcrumbs in captured events).
Similar callback is already implemented in Android and Cocoa SDKs.
Related items:
- Add
beforeBreadcrumbhook sentry-unreal#807 - Use sentry-native
beforeBreadcrumbcallback instead of Unreal's custom solution sentry-unreal#1247
Key changes
- New public API:
sentry_before_breadcrumb_function_ttypedef andsentry_options_set_before_breadcrumbsetter - Invoke callback in
sentry_add_breadcrumbusing the discarded flag pattern to safely exit theSENTRY_WITH_OPTIONSfor-loop macro
Testing
- Unit tests: discard, modify and passthrough cases considered
- Integration tests: modify and discard breadcrumbs paths