joshdholtz / Sentry-Android

[Deprecated] Use official "raven-java" library
https://github.com/getsentry/sentry-java
MIT License
180 stars 48 forks source link

Periodically retry uploads? #119

Closed edenman closed 7 years ago

edenman commented 7 years ago

If an event fails to upload for whatever reason, Sentry-Android currently doesn't retry the upload until the next app launch (unless I'm misreading the code). It might be nice if it did. You guys open to a PR doing this? Or should I just do this in my app layer by periodically calling Sentry.sendAllCachedCapturedEvents()?

marcomorain commented 7 years ago

I'm totally open to a PR for this. I'm not too familiar with the on-disk serialisation code. I guess the main issue to keep in mind is what happens when a new exception it triggered while loading/saving the previously captured events.

joshdholtz commented 7 years ago

@edenman I did not build this in initially because I wanted to keep this library as minimal as possible. I did not have a need for this and I also didn't want to risk having something running periodically like this in other people's apps :blush: I would prefer to keep this out of our feature set as it could introduce more bugs/maintenance and probably wouldn't be setup to how everyone would like to use it. It is probably best to keep doing this in your app layer for now unless you feel like opening up a PR like @marcomorain mentioned :heart:

edenman commented 7 years ago

I think it makes sense to not include this in the library. maybe just worth adding some documentation about the default behavior and that you should call sendAllCachedCapturedEvents periodically if you have a long-running app?

joshdholtz commented 7 years ago

@edenman I like that approach :ok_hand: I will add that to the documentation

edenman commented 7 years ago

For posterity/google-ability, here's what I have in a ActivityLifecycleCallbacks class:

  var firstResume = true
  var subscription: Subscription? = null

  override fun onActivityResumed(activity: Activity?) {
    // The first time we hit this, delay for 45 seconds: Sentry.init will have just done this.
    val initialDelaySeconds = if (firstResume) 45L else 0L
    subscription = Observable.interval(initialDelaySeconds, 45L, SECONDS)
        .observeOn(AndroidSchedulers.mainThread())
        .subscribe {
          Sentry.sendAllCachedCapturedEvents()
        }
    firstResume = false
  }

  override fun onActivityPaused(activity: Activity?) {
    subscription?.unsubscribe()
    subscription = null
  }