Permalink
Browse files

make collected user attributes customizable

  • Loading branch information...
1 parent ae9937f commit c3c0e3cf80fd9919ea167deebb8cbbc0e1bc579a @shime shime committed Sep 20, 2012
Showing with 25 additions and 3 deletions.
  1. +16 −2 README.md
  2. +6 −0 lib/airbrake/configuration.rb
  3. +3 −1 lib/airbrake/rails/controller_methods.rb
View
18 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
View
6 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
View
4 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
{}

0 comments on commit c3c0e3c

Please sign in to comment.