In our programs, there are these particular kinds of errors which might be transient. For these sorts of errors as a rule the time heals the injuries. Particularly when these occasions happen in Sidekiq job that may be simply retried. So mainly, we shouldn’t fear about them an excessive amount of. However… What if there’s an error reported in Honeybadger that prematurely disturbs the staff? Moreover, inflicting a lack of focus, which is pricey to regain, and pointless stress.
We don’t need to distracted for no cause
You’re guessing it proper that one thing like this occurred not too long ago within the challenge that I work on. So we began occupied with how we might clear up it to get notified, on our Slack channel, solely about exceptions that want our consideration.
Fortunately in that interval, we have been collectively at Arkency microcamp and the one solely Mirosław (thanks once more!) arrived on the white horse (or slightly his Kawasaki) and advised us in regards to the resolution they’ve carried out of their challenge.
Sidekiq DeathHandler to the rescue
The IgnoredError class is a wrapper for an error that has the potential to be transient. And therefore it could heal itself within the subsequent couple of occurrences.
class IgnoredError < StandardError
def message
trigger.examine
finish
finish
We even have so as to add the IgnoredError to honeybadger’s configuration, to ensure it’s not reported by default.
# honeybadger.yml
exceptions:
ignore:
- IgnoredError
Now, lets see how it might be utilized in manufacturing code
rescue BankAccountNotFound => exception
elevate IgnoredError
finish
The error would possibly happen for very totally different causes. One among them is that the occasions (within the Occasion-Pushed system) appeared in a distinct order than could be anticipated. And that’s okay. We don’t want to fret about that if we will merely retry the job and deal with the transient error. Therefore we will remodel this exception to IgnoredError
.
Within the happy-path state of affairs, after a retry (or few) is carried out in Sidekiq, the job is efficiently completed and the error will disappear.
However what if the error shouldn’t be transient?
In that case, the job shall be retried till it reaches a doable retries threshold after which it’ll name the dying handler.
Loss of life handlers are known as when all retries for a job have been exhausted and the job dies. As soon as it will get there, there’s data for us that the error most likely gained’t resolve itself and that guide intervention is required. In our case, we additionally need to be notified.
class IgnoredErrorReportingDeathHandler
def name(job, exception)
if exception.is_a?(IgnoredError)
ErrorNotifier.notify(
exception.trigger,
context: {
context: {
tags: "death_handler"
},
parameters: job,
element: job["class"]
}
)
finish
finish
finish
The final step is to easily register the IgnoredErrorReportingDeathHandler
in Sidekiq config
config.death_handlers << IgnoredErrorReportingDeathHandler.new
And also you’re good to go! Much less distractions, higher focus.