Repository navigation
Description
Description
Scope.Clone() copies data into the new scope through the public mutators, so cloning has side effects whenever scope sync is enabled (Android, iOS/Mac Catalyst, desktop Native AOT).
Clone() creates a new Scope and calls Apply(clone), which:
- calls
other.AddBreadcrumb(breadcrumb)for every breadcrumb. That re-runsBeforeBreadcrumband callsScopeObserver.AddBreadcrumbagain - calls
other.SetTag(key, value), which re-appliesTagFiltersand callsScopeObserver.SetTag - calls
User.CopyTo(other.User), which firesScopeObserver.SetUseronce per property - sets
other.Environment ??= Environment, which callsScopeObserver.SetEnvironment
Only attachments are copied directly, to avoid triggering a scope sync.
Hub clones the current scope on every CaptureEvent(..., configureScope) and CaptureFeedback(..., configureScope) call (1, 2). In non-global mode, PushScope also clones.
Impact
- Duplicate breadcrumbs in native crash reports. On MAUI, every
SentrySdk.CaptureException(ex, scope => ...)re-sends all existing breadcrumbs to the native SDK. - Tags from a per-event callback persist on the native scope. Tags, user or environment set inside the
configureScopecallback are meant for that one event, but reach the native scope through the observer and stay there. They then appear on later native crashes. BeforeBreadcrumbruns again on breadcrumbs it has already processed, on every clone. A callback that mutates breadcrumbs mutates them twice.- Native AOT servers re-sync the whole scope per request. In non-global mode with scope sync (e.g. an ASP.NET Core app published as Native AOT), every
PushScopere-syncs the whole scope.
Expected
Cloning a scope should produce an equivalent scope without calling the scope observer, BeforeBreadcrumb or TagFilters.
It's an open question whether mutations made on a temporary scope from a configureScope callback should sync to native at all. Since that scope is only used for a single event, probably not.
Notes
Found while researching #5197.
Activity
linear-code commentedon Sep 30, 2026
NET-833
fix: capturing with a configureScope callback no longer re-runs Befor…