Class: WhoopsRailsNotifier::ExceptionStrategy

Inherits:
WhoopsNotifier::Strategy
  • Object
show all
Defined in:
lib/whoops_rails_notifier/exception_strategy.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(strategy_name) ⇒ ExceptionStrategy

Returns a new instance of ExceptionStrategy.



4
5
6
7
8
9
10
11
# File 'lib/whoops_rails_notifier/exception_strategy.rb', line 4

def initialize(strategy_name)
  super
  
  self.service     = ::Rails.application.class.name.split("::").first.downcase
  self.environment = ::Rails.env
  
  add_report_builders
end

Instance Attribute Details

#environmentObject

Returns the value of attribute environment.



3
4
5
# File 'lib/whoops_rails_notifier/exception_strategy.rb', line 3

def environment
  @environment
end

#serviceObject

Returns the value of attribute service.



3
4
5
# File 'lib/whoops_rails_notifier/exception_strategy.rb', line 3

def service
  @service
end

Instance Method Details

#add_report_buildersObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/whoops_rails_notifier/exception_strategy.rb', line 13

def add_report_builders
  self.add_report_builder(:basic_details) do |report, evidence|
    report.service     = self.service
    report.environment = self.environment
    report.event_type  = "exception"
    report.message     = evidence[:exception].message
    report.event_time  = Time.now
  end
  
  self.add_report_builder(:details) do |report, evidence|
    exception = evidence[:exception]
    rack_env  = evidence[:rack_env]
    
    details = {}
    details[:backtrace] = exception.backtrace.collect{ |line|
      line.sub(/^#{ENV['GEM_HOME']}/, '$GEM_HOME').sub(/^#{Rails.root}/, '$Rails.root')
    }
    details[:params]    = rack_env["action_dispatch.request.parameters"]
    report.details      = details
  end

  self.add_report_builder(:create_event_group_identifier) do |report, evidence|
    identifier = "#{evidence[:controller]}##{evidence[:action]}"
    identifier << evidence[:exception].backtrace.collect{|l| l.sub(Rails.root, "")}.join("\n")
    report.event_group_identifier = Digest::MD5.hexdigest(identifier)
  end
end