Yesterday I wrote a little Ruby script to fetch Airbrake’s error groups. The main goal was to identify the most common errors.
The script started as a single file blob of code. After some refactoring I
created two main classes:
Use this class to retrieve error groups, see more at Airbrake API Reference - Groups v4. Create a new instance by providing your Airbrake API key and project id.
AirbrakeFetcher has two public methods:
fetch_groups(page, limit)to fetch a single page of error groups
fetch_all_groupsto fetch all error groups
fetch_all_groups doesn’t return anything, but yields objects returned by
fetch_groups for each page.
fetch_all_groups to collect data about error groups.
Use this class to build a textual bar chart from a list of couples
BarChart has one public method:
drawreturns a string representing a bar chart associated to instance’s data
draw to show the data I collected in the previous step with
draw is not the best name I could have chosen for this method. I
guess I could have called it
to_s, since it doesn’t have any drawing side
Below an example usage of both classes to show a bar chart of errors grouped by error type.
From an example execution on a Rails app, the most common error I found was
NoMethodError, that happens most of the time when you try to call a method on
What is your most common error?