Giter Site home page Giter Site logo

uber / rxdogtag Goto Github PK

View Code? Open in Web Editor NEW
645.0 16.0 19.0 1.73 MB

Automatic tagging of RxJava 2+ originating subscribe points for onError() investigation.

Home Page: https://uber.github.io/RxDogTag

License: Apache License 2.0

Shell 0.84% Java 86.71% Kotlin 12.45%
rxjava rxjava2 error-handling error-reporting java

rxdogtag's People

Contributors

dlew avatar emartynov avatar shaishavgandhi avatar tasomaniac avatar viakunin avatar zacsweers avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rxdogtag's Issues

Create delegate rules API, extract AutoDispose handling to separate artifact

Right now we've hardcoded AutoDispose support directly in. We should make an API that allows for provisioning of separate handlers to extract observers.

Let's start with something simple: accept a list of handlers, first one to consume it wins, otherwise built-in implementation takes over.

We can look later at doing something more Retrofit-style with delegating/forwarding if need be.

Issue with Proguard and AGP 7.0.2 (RxDogTag 1.0.1)

We recently encountered a weird issue after upgrading to the Android Gradle Plugin 7.0.2. When running our release build and therefore Proguard, the application crashes right at the start of the application with an ExceptionInInitializerError when RxDogTag.install() is called.

Stacktrace:

java.lang.ExceptionInInitializerError
        at com.uber.rxdogtag.RxDogTag$Builder.install(:483)
        at com.uber.rxdogtag.RxDogTag.install(:103)
        at com.mikef.rxdogtagissue.DogTagApplication.onCreate(:12)
        at android.app.Instrumentation.callApplicationOnCreate(Instrumentation.java:1192)
        at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6712)
        at android.app.ActivityThread.access$1300(ActivityThread.java:237)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1913)
        at android.os.Handler.dispatchMessage(Handler.java:106)
        at android.os.Looper.loop(Looper.java:223)
        at android.app.ActivityThread.main(ActivityThread.java:7656)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String java.lang.Package.getName()' on a null object reference
        at com.uber.rxdogtag.RxDogTag$Configuration.<clinit>

After investigating this issue a little bit I found the root cause in our Proguard configuration:

-repackageclasses ''

When this is set the aforementioned issue occurs. When going back to AGP 4.2.2 there is no issue, same thing when we remove this flag. I can't tell exactly why exactly this happens and whether it is the fault of RxDogTag or the Android Gradle Plugin.
For we now we removed this Proguard flag in order to solve the issue.

I've also created a super simple sample repository in order to reproduce this issue.

Library version:
1.0.1

ANR in 0.2.0

Library version: 0.2.0

Repro steps or stacktrace:

Getting an ANR, and while I can't really pinpoint that RxDogTag is the issue, it does show up in the stacktrace in my bugsnag logs. Feel free to close if it's not an issue with RxDogTag.

ANR: Application did not respond for at least 5000 ms
        at android.os.BinderProxy.transactNative(Binder.java:-2)
        at android.os.BinderProxy.transact(Binder.java:1140)
        at android.app.IActivityManager$Stub$Proxy.handleApplicationCrash(IActivityManager.java:3560)
        at com.android.internal.os.RuntimeInit$KillApplicationHandler.uncaughtException(RuntimeInit.java:143)
        at com.bugsnag.android.ExceptionHandler.uncaughtException(ExceptionHandler.java:91)
        at com.mixpanel.android.mpmetrics.ExceptionHandler.uncaughtException(ExceptionHandler.java:53)
        at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1068)
        at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:1063)
        at io.reactivex.plugins.RxJavaPlugins.uncaught(RxJavaPlugins.java:429)
        at io.reactivex.plugins.RxJavaPlugins.onError(RxJavaPlugins.java:383)
        at com.uber.rxdogtag.RxDogTag.reportError(RxDogTag.java:309)
        at com.uber.rxdogtag.DogTagObserver.onError(DogTagObserver.java:61)
        at io.reactivex.internal.operators.observable.ObservableObserveOn$ObserveOnObserver.checkTerminated(ObservableObserveOn.java:281)
        at io.reactivex.internal.operators.observable.ObservableObserveOn$ObserveOnObserver.drainNormal(ObservableObserveOn.java:172)
        at io.reactivex.internal.operators.observable.ObservableObserveOn$ObserveOnObserver.run(ObservableObserveOn.java:255)
        at io.reactivex.android.schedulers.HandlerScheduler$ScheduledRunnable.run(HandlerScheduler.java:124)
        at android.os.Handler.handleCallback(Handler.java:873)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loop(Looper.java:214)
        at android.app.ActivityThread.main(ActivityThread.java:6981)
        at java.lang.reflect.Method.invoke(Method.java:-2)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1445)

Consider kotlin rewrite

Things like the guardedDelegateCall are great candidates for inlining. Worth benchmarking too once #17 is done

1.0 Proposal

RxDogTag has had some time to incubate and we'd like to propose going 1.0. There aren't any major breaking API changes that we anticipate so we'd be planning to go to 1.0 soon.

If you have any concerns or things you want to get added before 1.0, now is the time!

If things go fine, we plan on doing 1.0 that targets RxJava 2 and a quick 2.0 which targets RxJava 3.

Add performance impact stats to README

There is no information about it in README.

I looked at android-benchmark, but it was unclear to me.

For example, it mentions guardedDelegateEnabled, which I do not see mentioned in README.

OnErrorNotImplementedException’s stacktrace isn’t cleared out when it should be

Stacktrace:

2019-09-18 08:46:44.148 13557-13557/com.example.moshisample E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.moshisample, PID: 13557
    io.reactivex.exceptions.OnErrorNotImplementedException: Non-null value 'person' was null at $.person
    Caused by: com.squareup.moshi.JsonDataException: Non-null value 'person' was null at $.person
        at com.example.moshisample.MainActivity.button1Clicked(MainActivity.kt:54)
        at [[ ↑↑ Inferred subscribe point ↑↑ ]].(:0)
        at [[ ↓↓ Original trace ↓↓ ]].(:0)
        at com.example.moshisample.PersonJsonAdapter.fromJson(PersonJsonAdapter.kt:25)
        at com.example.moshisample.PersonJsonAdapter.fromJson(PersonJsonAdapter.kt:12)
        at com.squareup.moshi.JsonAdapter$2.fromJson(JsonAdapter.java:137)
        at retrofit2.converter.moshi.MoshiResponseBodyConverter.convert(MoshiResponseBodyConverter.java:45)
        at retrofit2.converter.moshi.MoshiResponseBodyConverter.convert(MoshiResponseBodyConverter.java:27)
        at retrofit2.OkHttpCall.parseResponse(OkHttpCall.java:225)
        at retrofit2.OkHttpCall.execute(OkHttpCall.java:188)
        at retrofit2.adapter.rxjava2.CallExecuteObservable.subscribeActual(CallExecuteObservable.java:45)
        at io.reactivex.Observable.subscribe(Observable.java:12267)
        at io.reactivex.internal.operators.observable.ObservableSubscribeOn$SubscribeTask.run(ObservableSubscribeOn.java:96)
        at io.reactivex.Scheduler$DisposeTask.run(Scheduler.java:578)
        at io.reactivex.internal.schedulers.ScheduledRunnable.run(ScheduledRunnable.java:66)
        at io.reactivex.internal.schedulers.ScheduledRunnable.call(ScheduledRunnable.java:57)
        at java.util.concurrent.FutureTask.run(FutureTask.java:266)
        at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
        at java.lang.Thread.run(Thread.java:764)

Android app build.gradle

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

android {
    compileSdkVersion 29
    defaultConfig {
        applicationId "com.example.moshisample"
        minSdkVersion 23
        targetSdkVersion 29
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        targetCompatibility = "8"
        sourceCompatibility = "8"
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'androidx.appcompat:appcompat:1.0.2'
    implementation 'androidx.core:core-ktx:1.0.2'
    implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
    testImplementation 'junit:junit:4.12'
    androidTestImplementation 'androidx.test.ext:junit:1.1.1'
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
    implementation 'com.squareup.retrofit2:retrofit:2.6.1'
    implementation 'com.squareup.retrofit2:converter-moshi:2.6.1'
    kapt 'com.squareup.moshi:moshi-kotlin-codegen:1.8.0'
    implementation 'com.squareup.retrofit2:adapter-rxjava2:2.6.1'
    implementation "io.reactivex.rxjava2:rxjava:2.2.8"
    implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
    implementation("com.uber.rxdogtag:rxdogtag:0.2.0")
}

MainActivity.kt

import android.os.Bundle
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.squareup.moshi.JsonClass
import com.uber.rxdogtag.RxDogTag
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import kotlinx.android.synthetic.main.activity_main.*
import okhttp3.OkHttpClient
import retrofit2.Response
import retrofit2.Retrofit
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
import retrofit2.converter.moshi.MoshiConverterFactory
import retrofit2.http.GET


class MainActivity : AppCompatActivity() {

    lateinit var client: OkHttpClient
    lateinit var retrofit: Retrofit
    lateinit var service: MyService

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        RxDogTag.install()

        client = OkHttpClient.Builder()
            .build()

        retrofit = Retrofit.Builder()
            .baseUrl("http://www.mocky.io/v2/")
            .client(client)
            .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
            .addConverterFactory(MoshiConverterFactory.create())
            .build()

        service = retrofit.create(MyService::class.java)

        button1.setOnClickListener { button1Clicked() }

    }

    fun button1Clicked() {
        val call = service.getPersonExplicitNull()

        call.subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe({ t: Response<Person>? ->
                Toast.makeText(this@MainActivity, "Success", Toast.LENGTH_LONG).show()
            })
    }
}

interface MyService {
    //JSON:
    //    {
    //        "person": null
    //    }
    @GET("5d4da01d3300004b4433793d?mocky-delay=1000ms")
    fun getPersonExplicitNull(): Observable<Response<Person>>
}

@JsonClass(generateAdapter = true)
data class Person(
    val person: String = ""
)

Version 2.0.0 Tracking Issue

Checklist

  • Upgrade to RxJava 3 and AutoDispose 2
  • Package rename to rxdogtag2
  • Update Mkdocs to publish both 1.x and 2.x APIs
  • Update maven coords to rxdogtag2
  • Update benchmark with RxJava 3

Builder API for installation

After some more discussions with folks offline, let's add a couple options for configuring how traces are set up. These are to help improve grouping for crash processors that might otherwise index on the annotations in the stacktrace

  • Builder API for installation (similar to LeakCanary's)
  • One option to append a comment to the cause message that says the next line is an inferred subscribe point, and remove the annotations from the stacktrace.
  • One option to make the inferred subscribe point the first element in the trace, move the annotations all below it and indicate that the line above them is the inferred subscribe point

CompositeException example

Someone was asking about this, would be good to have an example of this in the wiki and maybe even a test

Error: "... only supported starting with Android N... "

When trying to compile I get this error:

"Default interface methods are only supported starting with Android N (--min-api 24): io.reactivex.CompletableObserver com.uber.rxdogtag.ObserverHandler.handle(io.reactivex.Completable, io.reactivex.CompletableObserver)"

Is this expected?

My setup:
minSdkVersion 21
targetSdkVersion 29
multiDexEnabled true

Alternative solutions

Right now, RxDogTag is implemented via throwing an exception and capturing the stack frame at that point. While we haven't seen any measurable performance impact at a macro level, it's certainly not free either. This issue exists to capture possible alternative implementation ideas.

Bytecode transformer

Recognizes certain subscribe() signatures and re-weaves them to have the hardcoded subscribe tag present with a custom tagging observer. Cost is just a string then.

  • Pros:
    • Effectively zero runtime overhead
  • Cons:
    • Invasive
    • Potentially mangles stacktraces
    • Could impact build times
    • Unclear what API could/would be used, or if line/method/class information is available.

Compiler plugin

Recognizes certain subscribe() signatures and re-weaves them to have the hardcoded subscribe tag present with a custom tagging observer. Cost is just a string then.

  • Pros:
    • Effectively zero runtime overhead
    • Should be low-to-no overhead with build times. Cacheable as part of compilation
  • Cons:
    • Invasive
    • Potentially mangles stacktraces
    • Language-dependent
    • No formally public APIs for Java or Kotlin, just non-public ones
    • Unclear what API could/would be used, or if line/method/class

Add an opt-in to call onError anyway

This way, if someone supplies their own LambdaConsumerIntrospection, they could control this behavior if they want (such as if theirs just logs an error)

How can I make a jar file of this Project?

Library version:

Repro steps or stacktrace:

Hi, dear devloper,
I wonder how could I make a jar file of rxdogtag. Since our workplace is offline. All dependence is jar file, including rxjava2. Is there a way to package this to jar file? I notice there are some maven dependence, like these:

  id 'ru.vyarus.animalsniffer'
  id 'me.champeau.gradle.jmh'
  id 'org.jetbrains.dokka'

What role do they play. Is it nessary package all of them to jar file?

Common crash report for all crashes - Rx v3.0.4 + RxDogTag v2.0.1

Library version: 2.0.1

Repro steps or stacktrace:

Crash 1:

Caused by java.lang.NumberFormatException: For input string: ""
       at rxdogtag2.-$$Lambda$RxDogTag$YP26HIb1nhHqbV4QlRgnyBuwHqU.apply(-.java:6)
       at [[ ↑↑ Inferred subscribe point ↑↑ ]].([[ ↑↑ Inferred subscribe point ↑↑ ]].java)
       at [[ Originating callback: onNext ]].([[ Originating callback: onNext ]].java)
       at [[ ↓↓ Original trace ↓↓ ]].([[ ↓↓ Original trace ↓↓ ]].java)
       at java.lang.Integer.parseInt(Integer.java:627)
       at java.lang.Integer.parseInt(Integer.java:650)
       at .....

Crash 2:

Caused by java.lang.IllegalArgumentException: No enum constant x.y.z.ECONOMY
       at rxdogtag2.-$$Lambda$RxDogTag$YP26HIb1nhHqbV4QlRgnyBuwHqU.apply(-.java:6)
       at [[ ↑↑ Inferred subscribe point ↑↑ ]].([[ ↑↑ Inferred subscribe point ↑↑ ]].java)
       at [[ Originating callback: onNext ]].([[ Originating callback: onNext ]].java)
       at [[ ↓↓ Original trace ↓↓ ]].([[ ↓↓ Original trace ↓↓ ]].java)
       at java.lang.Enum.valueOf(Enum.java:257)

both have the common line
at rxdogtag2.-$$Lambda$RxDogTag$YP26HIb1nhHqbV4QlRgnyBuwHqU.apply(-.java:6)

which is causing all crashes to merge under a single report

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.