Skip to content

Commit

Permalink
make collected user attributes customizable
Browse files Browse the repository at this point in the history
  • Loading branch information
shime committed Sep 20, 2012
1 parent ae9937f commit c3c0e3c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 3 deletions.
18 changes: 16 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions lib/airbrake/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 != ''
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion lib/airbrake/rails/controller_methods.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
{}
Expand Down

0 comments on commit c3c0e3c

Please sign in to comment.