Module: Roqua::Support::Errors

Defined in:
lib/roqua/support/errors.rb

Class Method Summary collapse

Class Method Details

.extra_parametersObject



4
5
6
# File 'lib/roqua/support/errors.rb', line 4

def self.extra_parameters
  @extra_parameters || {}
end

.extra_parameters=(hash) ⇒ Object



8
9
10
# File 'lib/roqua/support/errors.rb', line 8

def self.extra_parameters=(hash)
  @extra_parameters = hash
end

.report(exception, extra_params = {}) ⇒ Object



12
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
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/roqua/support/errors.rb', line 12

def self.report(exception, extra_params = {})
  return if const_defined?(:Rails) and Rails.env.test?
  parameters = extra_parameters.merge(extra_params)

  # Notify Roqua logging
  if Roqua.respond_to?(:logger)
    Roqua.logger.error('roqua.exception',
                       class_name: exception.class.to_s,
                       message: exception.message,
                       backtrace: exception.backtrace,
                       parameters: parameters)
  end

  # Notify Airbrake
  if const_defined?(:Airbrake)
    Airbrake.notify_or_ignore(exception, parameters: parameters)
  end

  # Notify AppSignal
  if const_defined?(:Appsignal) and
     not Appsignal.is_ignored_exception?(exception)
    # TODO: If and when https://github.com/appsignal/appsignal/pull/9 is merged,
    # this functionality should be supported directly by Appsignal.send_exception.
    # Appsignal.send_exception(exception, parameters: parameters)

    if Appsignal.active?
      # Hackety hack around stateful mess of Appsignal gem
      if Appsignal::Transaction.current
        Appsignal::Transaction.current.set_tags(parameters)
        Appsignal::Transaction.current.add_exception(exception)
      else
        transaction = Appsignal::Transaction.create(SecureRandom.uuid, ENV.to_hash)
        transaction.set_tags(parameters)
        transaction.add_exception(exception)
        transaction.complete!
        Appsignal.agent.send_queue
      end
    end
  end
end