diff --git a/README.md b/README.md index 34a8ba68e..4cf8e49e5 100644 --- a/README.md +++ b/README.md @@ -240,7 +240,7 @@ automatically in a controller, Airbrake sets that value. If you're, however, cal Current user information ------------------------ Airbrake provides information about the current logged in user, so you -could easily determine the user who experienced the error in your app. +can easily determine the user who experienced the error in your app. It uses `current_user` and `current_member` to identify the authenticated user, where `current_user` takes precendence. @@ -251,9 +251,23 @@ controller: alias_method :current_duck, :current_user helper_method :current_duck -Voila! You'll get information about a duck that experienced crash about +Voila! You'll get information about a duck that experienced a crash of your app. +By default Airbrake collects the following attributes: +* id +* name +* username +* email + +You can also customize attributes that will be collected + + Airbrake.configure do |config| + ... + # collect only user ids + config.user_attributes = [:id] # ["id"] also works + end + Asynchronous notifications with Airbrake ---------------------------------------- When your user experiences error using your application, it gets sent to diff --git a/lib/airbrake/configuration.rb b/lib/airbrake/configuration.rb index 24432468d..c963b913b 100644 --- a/lib/airbrake/configuration.rb +++ b/lib/airbrake/configuration.rb @@ -100,9 +100,14 @@ class Configuration # (boolean or nil; set to nil to catch exceptions when rake isn't running from a terminal; default is nil) attr_accessor :rescue_rake_exceptions + # User attributes that are being captured + attr_accessor :user_attributes + DEFAULT_PARAMS_FILTERS = %w(password password_confirmation).freeze + DEFAULT_USER_ATTRIBUTES = %w(id name username email).freeze + DEFAULT_BACKTRACE_FILTERS = [ lambda { |line| if defined?(Airbrake.configuration.project_root) && Airbrake.configuration.project_root.to_s != '' @@ -152,6 +157,7 @@ def initialize @framework = 'Standalone' @user_information = 'Airbrake Error {{error_id}}' @rescue_rake_exceptions = nil + @user_attributes = DEFAULT_USER_ATTRIBUTES.dup end # Takes a block and adds it to the list of backtrace filters. When the filters diff --git a/lib/airbrake/rails/controller_methods.rb b/lib/airbrake/rails/controller_methods.rb index 8977a6d05..9d76d9127 100644 --- a/lib/airbrake/rails/controller_methods.rb +++ b/lib/airbrake/rails/controller_methods.rb @@ -75,7 +75,9 @@ def airbrake_request_url def airbrake_current_user user = begin current_user rescue current_member end user.attributes.select do |k, v| - /^(id|name|username|email)$/ === k unless v.blank? + Airbrake.configuration. + user_attributes.map(&:to_sym). + include? k.to_sym unless v.blank? end.symbolize_keys rescue NoMethodError, NameError {}