Class: ExceptionNotifier::ExceptionTrackNotifier

Inherits:
BaseNotifier
  • Object
show all
Defined in:
lib/exception_notifier/exception_track_notifier.rb

Instance Method Summary collapse

Constructor Details

#initialize(_options) ⇒ ExceptionTrackNotifier

Returns a new instance of ExceptionTrackNotifier.



6
# File 'lib/exception_notifier/exception_track_notifier.rb', line 6

def initialize(_options); end

Instance Method Details

#call(exception, _options = {}) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/exception_notifier/exception_track_notifier.rb', line 8

def call(exception, _options = {})
  return unless ExceptionTrack.config.enabled_env?(Rails.env)

  # send the notification
  title = exception.message || "None"

  messages = []
  messages << headers_for_env(_options[:env])
  messages << ""
  messages << "--------------------------------------------------"
  messages << ""
  messages << exception.inspect
  unless exception.backtrace.blank?
    messages << "\n"
    messages << exception.backtrace
  end

  ExceptionTrack::Log.create(title: title[0, 200], body: messages.join("\n"))
end

#headers_for_env(env) ⇒ Object

Log Request headers from Rack env



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/exception_notifier/exception_track_notifier.rb', line 29

def headers_for_env(env)
  return "" if env.blank?

  parameters = env["action_dispatch.request.parameters"] || {}

  headers = []
  headers << "Method:      #{env['REQUEST_METHOD']}"
  headers << "URL:         #{env['REQUEST_URI']}"
  headers << "Controller:  #{parameters['controller']}##{parameters['action']}"
  headers << "RequestId:   #{env['action_dispatch.request_id']}"
  headers << "User-Agent:  #{env['HTTP_USER_AGENT']}"
  headers << "Remote IP:   #{env['REMOTE_ADDR']}"
  headers << "Language:    #{env['HTTP_ACCEPT_LANGUAGE']}"
  headers << "Server:      #{Socket.gethostname}"
  headers << "Process:     #{$PROCESS_ID}"

  headers.join("\n")
end