-
Notifications
You must be signed in to change notification settings - Fork 26
Extracting exception info
Bjørn Trondsen edited this page Apr 25, 2014
·
10 revisions
Here are some examples of information you might want to extract. Feel free to extend this page.
If you are going to store a lot of parameters, you may want to consider using ActiveRecord serialization to store some of the information in the same database field. Serialization example.
# Check out ActionDispatch::Request and Rack::Request for more options
config.store_request_info do |storage,request|
storage[:target_url] = request.url
storage[:http_method] = request.request_method
storage[:params] = request.params.inspect
storage[:referer_url] = request.referer
storage[:remote_ip] = request.remote_ip
storage[:user_agent] = request.user_agent
end
config.store_exception_info do |storage,exeception|
storage[:class_name] = exception.class.to_s
storage[:message] = exception.to_s
storage[:trace] = exception.backtrace.join("\n")
end
config.store_environment_info do |storage,env|
storage[:gateway_interface] = env["GATEWAY_INTERFACE"]
# Here is just a small part of what is available in the environment hash:
#env["PATH_INFO"]
#env["QUERY_STRING"]
#env["REMOTE_ADDR"]
#env["REMOTE_HOST"]
#env["REQUEST_METHOD"]
#env["REQUEST_URI"]
#env["SCRIPT_NAME"]
#env["SERVER_NAME"]
#env["SERVER_PORT"]
#env["SERVER_PROTOCOL"]
#env["SERVER_SOFTWARE"]
#env["HTTP_HOST"]
#env["HTTP_CONNECTION"]
#env["HTTP_USER_AGENT"]
#env["HTTP_ACCEPT"]
#env["HTTP_ACCEPT_ENCODING"]
#env["HTTP_ACCEPT_LANGUAGE"]
#env["HTTP_ACCEPT_CHARSET"]
#env["HTTP_COOKIE"]
end
config.store_global_info do |storage|
# This method doesnt provide anything that the other methods doesnt.
# It is just there to help you keep the storage configuration tidy.
storage[:app_name] = Rails.application.class.parent_name
storage[:created_at] = Time.zone.now
end