Capturing Data from Airbrake
This weekend I fixed an issue where a webform failed to write to its database. The app was set up with Airbrake, so I was able to grab the data pretty easily using Ruby and the Airbrake gem to collect the post parameters!
I created a file called ‘setup.rb’ to easily connect to my account:
require 'airbrake-api'
AirbrakeAPI.configure do |config|
config.account = '
config.auth_token = '
config.secure = true
end
Then I loaded it in Ruby’s interactive console:
irb
> load 'setup.rb'
> e = AirbrakeAPI.errors; nil
; nil makes it so all the errors don’t spew out to the console
if you get the error: "AirbrakeAPI::AirbrakeError: You are not authorized to see that page"
then your auth_token may be wrong. The first time I did this, I used my API key instead (since that was in the config in my app). I found my auth token in the account settings in the Airbrake web app.
Then I could access errors by index (they are ordered the same as in the web app) after inspecting various errors, I picked the one of interest and grabbed its id.
> e[6].id
=> 53112816
Then I could get all of the “notices” for that error like this
> n = AirbrakeAPI.notices(53112816); nil
I checked n.length
to verify that I’ve got the same number of notices as I saw in the console
Inspect the Notice object as yaml
> y n[0]
Then looks at the specific request parameters
> n[0].request.params
At last I could get all of the unique emails that were submitted to my form.
emails = n.map { |notice| notice.request.params['email'] unless notice.request.nil? }.uniq
An unexpectedly easy recovery strategy.