Skip to content

Conversation

@jpnurmi
Copy link
Collaborator

@jpnurmi jpnurmi commented Oct 24, 2025

Fixes: #3828

Deliver network and system event (battery) breadcrumbs in the main thread on Android, to avoid calling the C# beforeBreadcrumb callback from unmanaged internal Android worker threads, which can result in obscure and hard to debug crashes (#3828 (comment)).

Manually tested with Sentry.Samples.Maui and the following beforeBreadcrumb callback in MauiProgram.cs:

options.SetBeforeBreadcrumb((crumb, hint) =>
{
    var threadId = Thread.CurrentThread.ManagedThreadId;
    var threadName = Thread.CurrentThread.Name ?? (MainThread.IsMainThread ? "MAIN" : "WORKER");
    var crumbData = crumb.Data != null ? string.Join(", ", crumb.Data.Select(kv => $"{kv.Key}={kv.Value}")) : "null";
    Console.WriteLine($"[{threadName}:{threadId}] BeforeBreadcrumb Message={crumb.Message ?? "null"}, Level={crumb.Level}, Type={crumb.Type}, Category={crumb.Category}, Data={{{crumbData}}}");
    return crumb;
});

Before

11-03 11:06:55.598 10782 10806 I DOTNET  : [WORKER:6] BeforeBreadcrumb Message=null, Level=Info, Type=system, Category=network.event, Data={upload_bandwidth=12000, action=NETWORK_CAPABILITIES_CHANGED, vpn_active=false, signal_strength=-50, network_type=wifi, download_bandwidth=30000}
11-03 11:07:09.464 10782 10810 I DOTNET  : [WORKER:8] BeforeBreadcrumb Message=null, Level=Info, Type=system, Category=device.event, Data={level=50, charging=false, action=BATTERY_CHANGED}

After

11-03 11:09:05.534 11756 11756 I DOTNET  : [MAIN:1] BeforeBreadcrumb Message=null, Level=Info, Type=system, Category=network.event, Data={upload_bandwidth=12000, action=NETWORK_CAPABILITIES_CHANGED, vpn_active=false, signal_strength=-50, network_type=wifi, download_bandwidth=30000}
11-03 11:09:59.002 11756 11756 I DOTNET  : [MAIN:1] BeforeBreadcrumb Message=null, Level=Info, Type=system, Category=device.event, Data={level=1, charging=false, action=BATTERY_CHANGED}

Depends on:

@codecov
Copy link

codecov bot commented Oct 24, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (version6@a739982). Learn more about missing BASE report.

Additional details and impacted files
@@             Coverage Diff             @@
##             version6    #4671   +/-   ##
===========================================
  Coverage            ?   73.17%           
===========================================
  Files               ?      480           
  Lines               ?    17421           
  Branches            ?     3437           
===========================================
  Hits                ?    12748           
  Misses              ?     3822           
  Partials            ?      851           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jpnurmi jpnurmi force-pushed the jpnurmi/android-breadcrumbs branch from 9292bc2 to 2122303 Compare November 3, 2025 08:33
@jpnurmi jpnurmi force-pushed the jpnurmi/android-breadcrumbs branch from 2122303 to d43ead6 Compare November 3, 2025 08:37
@jpnurmi jpnurmi marked this pull request as ready for review November 3, 2025 10:14
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.

NETWORK_CAPABILITIES_CHANGED and BATTERY_CHANGED events on Android (with Maui) causing SIGSEGV Segfault

2 participants