Skip to content

System event breadcrumbs are delivered in a background thread #4701

Closed as duplicate

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 system events (e.g. battery changes)

  5. Observe thread ID and name in the logcat output

    2025-09-05 11:08:29.938  8476-8574  MainActivity            com.example.sentryandroidapp         D  ### [SystemEventsReceiver] BREADCRUMB: message=null, type=system, level=INFO, category=device.event, action=BATTERY_CHANGED
    

Expected Result

For system event breadcrumbs, beforeBreadcrumb is called in the main thread, not in SystemEventsReceiver thread. Is it possible to post system event breadcrumbs back to the main thread with the help of MainLooperHandler Looper.myLooper?

Actual Result

System event breadcrumbs are added from the SystemEventsReceiver background thread:

This causes beforeBreadcrumb to be called in sentry-android's internal background thread 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. changed the title [-]System breadcrumbs are delivered in a background thread[/-] [+]System event breadcrumbs are delivered in a background thread[/+] on Sep 5, 2025
  4. stefanosiano commented on Sep 8, 2025

    @stefanosiano
    Contributor

    closing as duplicate of #4700 (the root cause and solution are the same)

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    AndroidBug

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions