lib/airbrake/rails/controller_methods.rb in airbrake-3.1.2 vs lib/airbrake/rails/controller_methods.rb in airbrake-3.1.3

- old
+ new

@@ -1,16 +1,19 @@ module Airbrake module Rails module ControllerMethods def airbrake_request_data - { :parameters => airbrake_filter_if_filtering(params.to_hash), + { + :parameters => airbrake_filter_if_filtering(params.to_hash), :session_data => airbrake_filter_if_filtering(airbrake_session_data), :controller => params[:controller], :action => params[:action], :url => airbrake_request_url, - :cgi_data => airbrake_filter_if_filtering(request.env) } + :cgi_data => airbrake_filter_if_filtering(request.env), + :user => airbrake_current_user + } end private # This method should be used for sending manual notifications while you are still @@ -18,11 +21,11 @@ def notify_airbrake(hash_or_exception) unless airbrake_local_request? Airbrake.notify(hash_or_exception, airbrake_request_data) end end - + def airbrake_local_request? if defined?(::Rails.application.config) ::Rails.application.config.consider_all_requests_local || (request.local? && (!request.env["HTTP_X_FORWARDED_FOR"])) else consider_all_requests_local || (local_request? && (!request.env["HTTP_X_FORWARDED_FOR"])) @@ -37,19 +40,19 @@ def airbrake_filter_if_filtering(hash) return hash if ! hash.is_a?(Hash) - + if respond_to?(:filter_parameters) # Rails 2 - filter_parameters(hash) + filter_parameters(hash) elsif defined?(ActionDispatch::Http::ParameterFilter) # Rails 3 ActionDispatch::Http::ParameterFilter.new(::Rails.application.config.filter_parameters).filter(hash) else hash end rescue hash - + end def airbrake_session_data if session.respond_to?(:to_hash) session.to_hash @@ -66,9 +69,17 @@ end url << request.fullpath url end + + def airbrake_current_user + user = current_user || current_member + user.attributes.select do |k, v| + /^(id|name|username|email)$/ === k unless v.blank? + end + rescue NoMethodError, NameError + {} + end end end end -