Repository navigation
fix: Isolate user callback failures - #4026
Conversation
Drop filtered items when user callbacks throw and fall back to the configured trace sample rate for sampler failures. Co-Authored-By: Gino Buenaflor <giancarlo.buenaflor@sentry.io> Co-Authored-By: Gino Buenaflor <giancarlo.buenaflor@sentry.io>
Semver Impact of This PRπ’ Patch (bug fixes) π Changelog PreviewThis is how your changes will appear in the changelog. Features
Fixes
π€ This preview updates automatically when you update the PR. |
Codecov Reportβ
All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## v10-branch #4026 +/- ##
=============================================
Coverage ? 88.81%
=============================================
Files ? 346
Lines ? 12531
Branches ? 0
=============================================
Hits ? 11130
Misses ? 1401
Partials ? 0
Flags with carried forward coverage won't be shown. Click here to find out more. β View full report in Codecov by Harness. |
Keep later debug messages from overwriting the callback exception captured by the test logger.
There was a problem hiding this comment.
π΅ Needs a closer look
Native breadcrumb callback failures can still leave the breadcrumb captured because the integration catches the exception before this runner.
Pull request overview
This PR isolates user callback failures by dropping affected data, preserving spans, and falling back to tracesSampleRate when sampling fails.
Changes:
- Adds callback-failure handling for events, transactions, breadcrumbs, logs, metrics, and processors.
- Preserves spans when span callbacks fail.
- Adds focused regression tests.
File summaries
| File | Summary |
|---|---|
packages/dart/test/telemetry/metric/metric_capture_pipeline_test.dart |
Tests metric suppression on callback failure. |
packages/dart/test/telemetry/log/log_capture_pipeline_test.dart |
Tests log suppression on callback failure. |
packages/dart/test/sentry_traces_sampler_test.dart |
Tests sampling fallback behavior. |
packages/dart/test/sentry_client_test.dart |
Tests event, transaction, feedback, and processor failure handling. |
packages/dart/test/scope_test.dart |
Tests breadcrumb suppression. |
packages/dart/lib/src/telemetry/metric/metric_capture_pipeline.dart |
Drops metrics when callbacks fail. |
packages/dart/lib/src/telemetry/log/log_capture_pipeline.dart |
Drops logs when callbacks fail. |
packages/dart/lib/src/sentry_traces_sampler.dart |
Falls back to the configured sampling rate. |
packages/dart/lib/src/sentry_client.dart |
Drops affected events and transactions on callback failure. |
packages/dart/lib/src/scope.dart |
Drops breadcrumbs on callback failure. |
packages/dart/lib/src/event_processor/run_event_processors.dart |
Drops processor output on exceptions. A moderate issue remains for native breadcrumbs whose callback exceptions are caught earlier by LoadContextsIntegration. |
Review details
Suppressed comments (1)
packages/dart/lib/src/event_processor/run_event_processors.dart:29
- This only drops exceptions that escape
processor.apply. Flutter'sLoadContextsIntegrationinvokesbeforeBreadcrumbdirectly and catches exceptions in its outerapplyhandler before returning the event, so a throwingbeforeBreadcrumbcallback for native breadcrumbs still leaves the event captured instead of dropping the failing breadcrumb as promised by this PR. Isolate that callback in the integration as well (skip the failed breadcrumb, or let the exception reach this runner).
processedEvent = null;
- Files reviewed: 11/11 changed files
- Comments generated: 0
- Review effort level: Lite
π‘ Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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 b1f5dea. Configure here.
Treat a throwing traces sampler as unconfigured so inherited decisions still take precedence over the static sample rate.

π Description
Drop events, transactions, feedback, breadcrumbs, logs, metrics, and processor output when their user callback throws. Keep spans, and fall back directly to
tracesSampleRatewhentracesSamplerthrows.π‘ Motivation and Context
Align Dart and Flutter callback error isolation with the SDK callback policy in Wrap all SDK user callbacks in a try catch. This intentionally changes runtime behavior and is based on
v10-branch.π How did you test it?
Added focused regression coverage for each changed fallback path.
git diff --check origin/v10-branch...HEADpasses. Local Dart execution was unavailable in the sandbox; CI will run the package suite.π Checklist
sendDefaultPiiis enabledvia Gino Buenaflor.
--
View Junior Session [Sentry]