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:

Key changes

  • New public API: sentry_before_breadcrumb_function_t typedef and sentry_options_set_before_breadcrumb setter
  • Invoke callback in sentry_add_breadcrumb using the discarded flag pattern to safely exit the SENTRY_WITH_OPTIONS for-loop macro

Testing

  • Unit tests: discard, modify and passthrough cases considered
  • Integration tests: modify and discard breadcrumbs paths