Skip to content

Network breadcrumbs are delivered in a background thread #4700

Closed

Description

@jpnurmi

Integration

sentry-android

Build System

Gradle

AGP Version

5.9.0

Proguard

Enabled

Version

8.19.0, 8.20.0

Steps to Reproduce

  1. Create Android app

  2. Run sentry-wizard

  3. Add beforeBreadcrumb callback

     options.beforeBreadcrumb = SentryOptions.BeforeBreadcrumbCallback { crumb, hint ->
         Log.d("MainActivity", "[${Thread.currentThread().name}] BREADCRUMB: message=${crumb.message}, type=${crumb.type}, level=${crumb.level}, category=${crumb.category}, action=${crumb.getData("action")}")
         crumb
    }
  4. Trigger network changes (e.g. adb shell svc wifi enable/disable)

  5. Observe thread ID and name in the logcat output

    2025-09-05 10:57:04.116  7369-7450  MainActivity            com.example.sentryandroidapp         D  [ConnectivityThread] BREADCRUMB: message=null, type=system, level=INFO, category=network.event, action=NETWORK_AVAILABLE
    2025-09-05 10:57:04.119  7369-7450  MainActivity            com.example.sentryandroidapp         D  [ConnectivityThread] BREADCRUMB: message=null, type=system, level=INFO, category=network.event, action=NETWORK_CAPABILITIES_CHANGED
    

Expected Result

For network breadcrumbs, beforeBreadcrumb is called in the main thread, not in Android's ConnectivityThread. Is it possible to use ConnectivityManager.registerDefaultNetworkCallback(NetworkCallback, Handler) [API26+] together with MainLooperHandler Looper.myLooper?

Actual Result

The network callback is registered without specifying a handler:

connectivityManager.registerDefaultNetworkCallback(networkCallback);

This causes beforeBreadcrumb to be called in Android's internal ConnectivityThread that downstream SDKs are not aware of, causing random hard-to-reproduce crashes down the line:

Activity

  1. added
    Bug
    on Sep 5, 2025
  2. moved this to Waiting for: Product Owner in GitHub Issues with 👀 3on Sep 5, 2025
  3. stefanosiano commented on Sep 8, 2025

    @stefanosiano
    Contributor

    Discussion is going on at getsentry/sentry-dotnet#3828
    We'll reply with the final decision here, too

  4. moved this from Waiting for: Product Owner to No status in GitHub Issues with 👀 3on Sep 8, 2025
  5. markushi commented on Sep 10, 2025

    @markushi
    Member

    Let's implement it as outlined here: getsentry/sentry-dotnet#3828 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

AndroidBug

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions