class Ridc::ExceptionReporter

Public Class Methods

new(app) click to toggle source
# File lib/exception_reporter.rb, line 4
def initialize(app)
        @app = app
end

Public Instance Methods

call(env) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source

thanks raygun4ruby guys!

# 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