Class: Ridc::ExceptionReporter

Inherits:
Object
  • Object
show all
Defined in:
lib/exception_reporter.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ ExceptionReporter

Returns a new instance of ExceptionReporter.



4
5
6
# File 'lib/exception_reporter.rb', line 4

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/exception_reporter.rb', line 8

def call(env)
  response = @app.call(env)
rescue Exception => exception
  #Rails.logger.original.info("yeah!")
  report(exception, env)
  raise exception
end

#form_data(rack_env) ⇒ Object



50
51
52
53
54
55
56
# File 'lib/exception_reporter.rb', line 50

def form_data(rack_env)
  request = Rack::Request.new(rack_env)

  if request.form_data?
    request.body
  end
end

#headers(rack_env) ⇒ Object



44
45
46
47
48
# File 'lib/exception_reporter.rb', line 44

def headers(rack_env)
  rack_env.select do |k, v|
    k.to_s.start_with?("HTTP_")
  end
end

#report(exception, environment) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/exception_reporter.rb', line 16

def report(exception, environment)
  event_session_id = Thread.current["session_id"]
  event_session_content = Thread.current["session_content"]

  event = {
    :event_type => "exception",
    :exception_class => exception.class.to_s,
    :description => exception.to_s, 
    :backtrace => Array(exception.backtrace).join("\n").to_s,
    :environment => useful_environment_parts(environment),
    :event_session_id => event_session_id,
    :event_session_content => event_session_content
  }
  Ridc.sender.add_to_queue(event)
end

#useful_environment_parts(env) ⇒ Object

thanks raygun4ruby guys!



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/exception_reporter.rb', line 32

def useful_environment_parts(env)
  {
    :hostName =>   env["SERVER_NAME"],
    :url =>         env["PATH_INFO"],
    :httpMethod =>  env["REQUEST_METHOD"],
    :ipAddress =>   env["REMOTE_ADDR"],
    :queryString => Rack::Utils.parse_nested_query(env["QUERY_STRING"]),
    :form =>        form_data(env),
    :headers =>    headers(env),
    :rawData =>     []
  }
end