RxJava2Debug

repository·master·Indexed 20 days ago

https://github.com/akaita/rxjava2debug

A library that makes RxJava2 StackTraces more meaningful by pointing directly to the source code that created the Rx pipeline. It provides tools to enable assembly tracking via enableRxJava2AssemblyTracking() and retrieve extended stack traces for handled exceptions using getEnhancedStackTrace(Throwable).

Tokens
1.2K
Snippets
8
Records
9
Agent score
21%

What's inside RxJava2Debug

  1. Enable RxJava2 assembly tracking

    master

    To make RxJava2 crash reports clear and unique, enable assembly tracking as early as possible in your application lifecycle.

    Important: You must call this method AFTER setting up any crash reporting mechanism (like Crashlytics or Fabric).

    If you provide basePackageNames, the library will ensure that Stack Traces contain a reference to your code within those packages. This also helps crash reporting systems (like Crashlytics) treat different RxJava pipelines as unique issues rather than bundling them into a single report.

    public class MyApplication extends Application {
    
        @Override
        public void onCreate() {
            super.onCreate();
            
            Fabric.with(this, new Crashlytics());
            
            // Enable RxJava assembly stack collection
            // Call this AFTER setting up Crash reporting
            RxJava2Debug.enableRxJava2AssemblyTracking(new String[]{"com.example.myapp", "com.example.mylibrary"});
        }
    }
  2. Install RxJava2Debug via Maven or JCenter

    master

    Add the following dependency to your project to enable enhanced StackTraces for RxJava2 streams.

    Using Maven Central:

    repositories {
        mavenCentral()
    }
    
    dependencies {
        compile 'com.akaita.java:rxjava2-debug:1.4.0'
    }

    Using JCenter:

    repositories {
        jcenter()
    }
    
    dependencies {
        compile 'com.akaita.java:rxjava2-debug:1.4.0'
    }
    dependencies {
        compile 'com.akaita.java:rxjava2-debug:1.4.0'
    }
  3. Obtain an enhanced StackTrace for handled exceptions

    master

    When you implement an onError handler in an RxJava2 stream, you can manually obtain an enhanced StackTrace that points to the exact line of code that created the issue in the Rx pipeline using RxJava2Debug.getEnhancedStackTrace(throwable).

    responseSubject
        .subscribe(
            responseObservable -> handleResponse(responseObservable),
            throwable -> RxJava2Debug.getEnhancedStackTrace(throwable)
        );
  4. Filter StackTrace to highlight specific packages

    master

    You can configure RxJava2Debug to prioritize specific package names in the generated StackTrace. When these packages are highlighted, they will appear at the top of the StackTrace, making it easier to identify the source of an issue. This is particularly useful when using error reporting systems like Crashlytics, as it helps prevent multiple RxJava2-related errors from being grouped into a single report entry, ensuring you get one distinct entry per crash.

    Use RxJava2Debug.enableRxJava2AssemblyTracking(String[] packages) to specify the packages you want to highlight.

    RxJava2Debug.enableRxJava2AssemblyTracking(new String[]{"com.akaita.fgas", "com.akaita.android"});
  5. enableRxJava2AssemblyTracking()

    master

    Starts collecting information about RxJava's execution to provide a more meaningful StackTrace in case of a crash.

    Beware: Any crash-reporting handler should be set up before calling this method.

    void enableRxJava2AssemblyTracking()
  6. enableRxJava2AssemblyTracking(String[] basePackageNames)

    master

    Starts collecting filtered information about RxJava's execution to provide a more meaningful StackTrace in case of a crash. The provided basePackageNames are used to ensure the StackTrace contains a reference to your code and to help crash reporting systems differentiate between unique pipelines.

    Beware: Any crash-reporting handler should be set up before calling this method.

    void enableRxJava2AssemblyTracking(@Nullable String[] basePackageNames)
  7. getEnhancedStackTrace(Throwable originalException)

    master

    Obtains a copy of the original Throwable with an extended StackTrace that points to the origin of the RxJava2 pipeline.

    @Nullable Throwable getEnhancedStackTrace(Throwable originalException)