3

When we are sending the airbrake error to the airbrake server, by default it includes the controller name and action name.

But the question is that I want to add some extra parameters like username, email of the current user. If anyone has any idea please suggest how to do that?

In my layout application.html:

- if ['development'].include?(Rails.env)
  = airbrake_javascript_notifier
  = render :partial => 'layouts/airbrake_notifier'

and in the partial I have written:

   Airbrake.errorDefaults['name'] = "#{current_user.name}";<br/>
   Airbrake.errorDefaults['email'] = "#{current_user.email}";<br/>
   Airbrake.errorDefaults['phone'] = "#{current_user.phone}";<br/>
   Airbrake.errorDefaults['title'] = "#{current_user.title;<br/>
Widor
  • 13,003
  • 7
  • 42
  • 64
tripurari
  • 71
  • 7

2 Answers2

1

Not a great solution, but the Airbrake Knowledge Base recommends essentially patching the airbrake gem source of the lib/airbrake/notice.rb file.

def initialize(args)
  ...
  self.parameters          = args[:parameters] ||
                               action_dispatch_params ||
                               rack_env(:params) ||
                               {'username' => current_user.name}

It would certainly be better to have this be configurable without patching source.

What I've done instead is simply add a few pieces of data to the session (current_user.name mainly), since session data is sent with the request. I wouldn't do this for more than a few little pieces of data.

mmrobins
  • 12,809
  • 7
  • 41
  • 42
  • 3
    Thanks! I got around this limitation in a background job by putting my stuff in the session param: `Airbrake.notify error, session: { car_id: car.id }` – AlexChaffee May 20 '15 at 19:04
1

We've just added getting current users into the Airbrake Gem. https://github.com/airbrake/airbrake/wiki/Sending-current-user-information

You'll soon be able to sort by current user in an upcoming redesign of the UI.

Ray Baxter
  • 3,181
  • 23
  • 27
Ben Arent
  • 1,017
  • 8
  • 8