Bugsnag Integration or How to Deal With Bugs Wisely
Do you sometimes find yourself Keanu Reeves from The Matrix, in the raining down code when you forced to go through the long log files to track the users’ errors? Well, actually I did, and I can claim for sure that it’s not a good experience at all.
However, it is always darkest before the dawn. And my daylight came when I had found Bugsnag, it’s a web platform that notifies about the errors and exceptions that occur in the service.
Previously, we had been using none of similar solutions and the process of finding information about the errors was quite complex and daunting. We gathered all needed data during a day, week and month then processed it and automatically formed reports. They included such info as account id, store url, response code, error message, etc. All reports were sent to clients via email with described exceptions.
Number of our clients has been increasing and it is turned to be more and more difficult to work and deal with multiple requests in such a way. But probably the main problem that occurred, was to react immediately when an error took place instead of waiting for the report. All these inconveniences have triggered for searching a solution that would help to solve the challenges and move to a higher quality level.
Bugsnag is a service that has met all our requirements. I can point out major features that have influenced on our decision:
- there is no error limitations in a definite time (while Rollbar or Sentry has);
- thetime of storing the errors history is longer than in other similar solutions (e.g. Rollbar and Sentry offer only 30 days while Bugsnag - 3 months);
- reach and well-structured Bugsnag documentation includes guides and instructions on how to get out the most of the platform. It allows to create your own notifier libraries and notification plugins;
- Bugsnag supports various notifications beginning from the old email to pinging the team’s HipChat. Over and above, it opens a GitHub issue directly in your repository, it’s a great feature, isn’t it? And the web hook notification will ring an alarm every 5 minute, so you surely won’t forget about an exception;
- and the final criteria is the price that is pretty reasonable for such options.
As I have mentioned above, Bugsnag documentation is well-structured and outlines best patterns on how to perform integration with the platform. The process is described in details and in absolutely simple way. So, this allows to set up everything if you don’t even have a background experience in working with such a type of service. You are able to add Bugsnag to your project in three ways:
I find this very useful and simple as you don’t have to download, unzip and paste various files. I have just used one command:
$ composer require "bugsnag/bugsnag:2.*"
A manual variant is given for those who don’t used to work with the composer.
Catching bugs in Bugsnag, is quite simple process. You just have to add error and exception handlers:
set_error_handler(array($bugsnag, 'errorHandler')); set_exception_handler(array($bugsnag, 'exceptionHandler'));
Note, if you have error and exception handlers written in your project, then keep an eye as several copies may seriously tie you up in knots.
Severity is one more useful feature that allows to set up error priority (e.g. info, error, warning). Thus, you can easily filter and fix the major of them primarily. Also, Severity will help you to separate exceptions happened on production or development servers.
Also, if there is a necessity, you can indicate a user who has faced an error. In some cases it’s highly important to contact the client immediately and help with the problem.
$bugsnag->setUser(array( 'name' => 'Leeroy Jenkins', 'email' => 'firstname.lastname@example.org' ));
The possibility to create various additional fields and set any other parameters is crucial in our project, so I use it in the full blast. Thus, I can send to Bugsnag all the necessary error details which are essential for the further work with an exception.
So, to put the finishing touch, it’s worth saying that Bugsnag helps us to diagnose errors and react on them immediately. It provides us with a possibility to make major system decisions in the shortest time. Hope, that my experience in using Bugsnag will be useful and helps you in your work.