Airbrake error backtrace summary

We often have an error with a few thousand occurances and want to find out which code paths caused it.

Usage
Use auth-token from settings page, not your api-key.

ruby airbrake_backtraces.rb your-account your-auth-token error-id

Output

Trace 1: occurred 597 times
...funky backtraces...
Trace 2: occurred 119 times
...funky backtraces...
Trace 3: occurred 13 times
...funky backtraces...

Code

#! /usr/bin/env ruby
# lists all sources of a given error
# http://grosser.it/2012/09/08/airbrake-error-summary
#
# gem install airbrake-api
# USAGE: ruby airbrake_backtraces.rb your-account your-auth-token error-id
# https://your-account.airbrake.io/errors/ID

require "airbrake-api"

AirbrakeAPI.account = ARGV[0] || raise("need airbrake account as ARGV[0]")
AirbrakeAPI.auth_token = ARGV[1] || raise("need airbrake token as ARGV[1], go to airbrake -> settings, copy your auth token")
AirbrakeAPI.secure = true

error_id = ARGV[2] || raise("need error id")
compare_depth = (ARGV[3] || 4).to_i

notices = AirbrakeAPI.notices(error_id, :pages => 20)
backtraces = notices.select{|n| n.backtrace }.group_by do |notice|
  notice.backtrace.first[1][0..compare_depth]
end

backtraces.sort_by{|k,t| t.size }.reverse.each_with_index do |(key, traces), index|
  puts "Trace #{index + 1}: occurred #{traces.size} times"
  puts key
  puts ""
end

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s