Class: Rnotifier::ExceptionData
- Inherits:
-
Object
- Object
- Rnotifier::ExceptionData
- Defined in:
- lib/rnotifier/exception_data.rb
Constant Summary collapse
- HEADER_REGX =
/^HTTP_/
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#exception ⇒ Object
readonly
Returns the value of attribute exception.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#request ⇒ Object
readonly
Returns the value of attribute request.
Instance Method Summary collapse
- #exception_data ⇒ Object
- #filtered_params ⇒ Object
- #fingerprint ⇒ Object
- #headers ⇒ Object
-
#initialize(exception, env, options = {}) ⇒ ExceptionData
constructor
A new instance of ExceptionData.
- #is_bot?(agent) ⇒ Boolean
- #notify ⇒ Object
- #rack_exception_data ⇒ Object
Constructor Details
#initialize(exception, env, options = {}) ⇒ ExceptionData
Returns a new instance of ExceptionData.
5 6 7 8 9 10 11 12 13 |
# File 'lib/rnotifier/exception_data.rb', line 5 def initialize(exception, env, = {}) @exception = exception @options = if [:type] == :rack @request = Rack::Request.new(env) else @env = env end end |
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
3 4 5 |
# File 'lib/rnotifier/exception_data.rb', line 3 def env @env end |
#exception ⇒ Object (readonly)
Returns the value of attribute exception.
3 4 5 |
# File 'lib/rnotifier/exception_data.rb', line 3 def exception @exception end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/rnotifier/exception_data.rb', line 3 def @options end |
#request ⇒ Object (readonly)
Returns the value of attribute request.
3 4 5 |
# File 'lib/rnotifier/exception_data.rb', line 3 def request @request end |
Instance Method Details
#exception_data ⇒ Object
51 52 53 54 55 56 57 58 59 60 |
# File 'lib/rnotifier/exception_data.rb', line 51 def exception_data e_data = { :class_name => exception.class.to_s, :message => exception., :backtrace => exception.backtrace, :fingerprint => (self.fingerprint rescue nil) } e_data[:code] = ExceptionCode.get(exception) if Config.capture_code e_data end |
#filtered_params ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/rnotifier/exception_data.rb', line 70 def filtered_params if rp = request.env['action_dispatch.parameter_filter'] ParameterFilter.filter(request.env['action_dispatch.request.parameters'] || request.params, rp) else ParameterFilter.default_filter(request.params) end end |
#fingerprint ⇒ Object
62 63 64 65 66 67 68 |
# File 'lib/rnotifier/exception_data.rb', line 62 def fingerprint #data[:fingerprint] = Digest::MD5.hexdigest("#{exception.message.gsub(/#<\w*:\w*>/, '')}#{data[:fingerprint]}") if exception.backtrace && !exception.backtrace.empty? Digest::MD5.hexdigest(exception.backtrace.join) end end |
#headers ⇒ Object
80 81 82 83 84 85 86 87 |
# File 'lib/rnotifier/exception_data.rb', line 80 def headers headers = {} request.env.each do |k, v| headers[k.sub(HEADER_REGX, '').downcase] = v if k =~ HEADER_REGX end headers['cookie'] = headers['cookie'].sub(/_session=\S+/, '_session=[FILTERED]') if headers['cookie'] headers end |
#is_bot?(agent) ⇒ Boolean
89 90 91 92 93 94 |
# File 'lib/rnotifier/exception_data.rb', line 89 def is_bot?(agent) return false if agent.nil? || Config.ignore_bots.nil? || Config.ignore_bots.empty? Config.ignore_bots.each { |bot| return true if (agent =~ Regexp.new(bot)) } false end |
#notify ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/rnotifier/exception_data.rb', line 15 def notify return false unless Config.valid? return false if Config.ignore_exceptions && Config.ignore_exceptions.include?(exception.class.to_s) return false if @options[:type] == :rack && is_bot?(@request.user_agent) begin data = [:type] == :rack ? self.rack_exception_data : {:extra => self.env } data[:app_env] = Rnotifier::Config.app_env data[:occurred_at] = Time.now.to_i data[:exception] = self.exception_data data[:context_data] = Thread.current[:rnotifier_context] if Thread.current[:rnotifier_context] data[:data_from] = [:type] data[:rnotifier_client] = Config::CLIENT return Notifier.send(data, Config.exception_path) rescue Exception => e Rlogger.error("[NOTIFY] #{e.}") Rlogger.error("[NOTIFY] #{e.backtrace}") false end end |
#rack_exception_data ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/rnotifier/exception_data.rb', line 37 def rack_exception_data data = {} data[:request] = { :url => request.url, :referer_url => request.referer, :ip => request.ip, :http_method => "#{request.request_method}#{' # XHR' if request.xhr?}", :params => filtered_params, :headers => self.headers, :session => request.session } data end |