Module: Caliper::AppError

Defined in:
lib/caliper/app_error.rb

Class Method Summary collapse

Class Method Details

.create(exception, request_env) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/caliper/app_error.rb', line 3

def self.create(exception, request_env)
  return unless Caliper.config[:enabled]

  req = ::Rack::Request.new(request_env)

  remote_ip = request_env["action_dispatch.remote_ip"]
  remote_ip = remote_ip.first if remote_ip.is_a?(Array)

  error_attributes = {
    "message" => exception.message,
    "class_name" => exception.class.name,
    "host" => Socket.gethostname,
    "request_data" => {
      "http_method" => request_env["REQUEST_METHOD"],
      "uri" => request_env["REQUEST_URI"],
      "path" => request_env["PATH_INFO"],
      "remote_ip" => "#{remote_ip}",
      "parameters" => req.params,
      "session_data" => req.session,
      "HTTP_USER_AGENT" => request_env["HTTP_USER_AGENT"],
      "HTTP_HOST" => request_env["HTTP_HOST"],
      "HTTP_X_REAL_IP" => request_env["HTTP_X_REAL_IP"],
      "HTTP_X_FORWARDED_FOR" => request_env["HTTP_X_FORWARDED_FOR"]
    }
  }
  error_attributes["backtrace"] = exception.backtrace.join("\n") if exception.backtrace

  CaliperApi.create_error(
    Yajl::Encoder.encode({"error" => error_attributes})
  )
end