Skip to content

fix: Isolate user callback failures - #4026

Merged
buenaflor merged 5 commits into
v10-branchfrom
fix/v10-callback-error-isolation
Sep 21, 2026
Merged

buenaflor merged 5 commits into
v10-branchfrom
fix/v10-callback-error-isolation

Conversation

@sentry-junior

@sentry-junior sentry-junior Bot commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

πŸ“œ Description

Drop events, transactions, feedback, breadcrumbs, logs, metrics, and processor output when their user callback throws. Keep spans, and fall back directly to tracesSampleRate when tracesSampler throws.

πŸ’‘ 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...HEAD passes. Local Dart execution was unavailable in the sandbox; CI will run the package suite.

πŸ“ Checklist

  • I reviewed submitted code
  • I added tests to verify changes
  • No new PII added or SDK only sends newly added PII if sendDefaultPii is enabled
  • I updated the docs if needed
  • All tests passing
  • Public API changes reviewed by another Mobile SDK team member or implemented according to the develop docs spec
  • No breaking changes

via Gino Buenaflor.

--

View Junior Session [Sentry]

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>
@github-actions

github-actions Bot commented Sep 17, 2026 •

Copy link
Copy Markdown
Contributor

Semver Impact of This PR

🟒 Patch (bug fixes)

πŸ“‹ Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


Features

  • (flutter) Revamp app-start frame spans by buenaflor in #4018

Fixes

  • Isolate user callback failures by sentry-junior[bot] in #4026

πŸ€– This preview updates automatically when you update the PR.

@codecov

codecov Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

Codecov Report

βœ… All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (v10-branch@71ca7a4). Learn more about missing BASE report.
βœ… All tests successful. No failed tests found.

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           
Flag Coverage Ξ”
sentry 88.63% <ΓΈ> (?)
sentry_dio 97.95% <ΓΈ> (?)
sentry_drift 93.63% <ΓΈ> (?)
sentry_file 64.41% <ΓΈ> (?)
sentry_firebase_remote_config 100.00% <ΓΈ> (?)
sentry_flutter 92.91% <ΓΈ> (?)
sentry_grpc 99.11% <ΓΈ> (?)
sentry_hive 76.37% <ΓΈ> (?)
sentry_isar 73.88% <ΓΈ> (?)
sentry_link 22.04% <ΓΈ> (?)
sentry_logging 97.01% <ΓΈ> (?)
sentry_sqflite 88.88% <ΓΈ> (?)
sentry_supabase 97.48% <ΓΈ> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

β˜” View full report in Codecov by Harness.
πŸ“’ Have feedback on the report? Share it here.

Keep later debug messages from overwriting the callback exception captured by the test logger.
@buenaflor
buenaflor marked this pull request as ready for review September 17, 2026 09:12
Copilot AI lite review requested due to automatic review settings September 17, 2026 09:12

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ”΅ 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's LoadContextsIntegration invokes beforeBreadcrumb directly and catches exceptions in its outer apply handler before returning the event, so a throwing beforeBreadcrumb callback 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.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ 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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants