module Raygun

Client for injecting JavaScript code for tracking front end exceptions raygun.com/docs/languages/javascript

Adapted from Bugsnag code as per Sidekiq 2.x comment request

SideKiq 2.x: github.com/mperham/sidekiq/blob/2-x/lib/sidekiq/exception_handler.rb Bugsnag: github.com/bugsnag/bugsnag-ruby/blob/master/lib/bugsnag/sidekiq.rb

Constants

CLIENT_NAME
CLIENT_URL

used to identify ourselves to Raygun

VERSION

Attributes

configuration[W]

Configuration Object (instance of Raygun::Configuration)

Public Class Methods

configuration() click to toggle source
# File lib/raygun.rb, line 43
def configuration
  @configuration ||= Configuration.new
end
configured?() click to toggle source
# File lib/raygun.rb, line 55
def configured?
  !!configuration.api_key
end
default_configuration() click to toggle source
# File lib/raygun.rb, line 47
def default_configuration
  configuration.defaults
end
deprecation_warning(message) click to toggle source
# File lib/raygun.rb, line 109
def deprecation_warning(message)
  if defined?(ActiveSupport::Deprecation)
    ActiveSupport::Deprecation.warn(message)
  else
    puts message
  end
end
failsafe_log(message) click to toggle source
# File lib/raygun.rb, line 105
def failsafe_log(message)
  configuration.failsafe_logger.info(message)
end
log(message) click to toggle source
# File lib/raygun.rb, line 99
def log(message)
  return unless configuration.debug

  configuration.logger.info("[Raygun] #{message}") if configuration.logger
end
record_breadcrumb( message: nil, category: '', level: :info, timestamp: Time.now.utc, metadata: {}, class_name: nil, method_name: nil, line_number: nil ) click to toggle source
# File lib/raygun.rb, line 75
def record_breadcrumb(
    message: nil,
    category: '',
    level: :info,
    timestamp: Time.now.utc,
    metadata: {},
    class_name: nil,
    method_name: nil,
    line_number: nil
)
  log('recording breadcrumb')

  Raygun::Breadcrumbs::Store.record(
    message: message,
    category: category,
    level: level,
    timestamp: timestamp,
    metadata: metadata,
    class_name: class_name,
    method_name: method_name,
    line_number: line_number,
  )
end
reset_configuration() click to toggle source
# File lib/raygun.rb, line 51
def reset_configuration
  @configuration = Configuration.new
end
setup() { |configuration| ... } click to toggle source
# File lib/raygun.rb, line 37
def setup
  yield(configuration)

  log("configuration settings: #{configuration.inspect}")
end
track_exception(exception_instance, env = {}, user = nil, retry_count = 1) click to toggle source
# File lib/raygun.rb, line 59
def track_exception(exception_instance, env = {}, user = nil, retry_count = 1)
  log('tracking exception')

  if configuration.send_in_background
    track_exception_async(exception_instance, env, user, retry_count)
  else
    track_exception_sync(exception_instance, env, user, retry_count)
  end
end
track_exceptions() { || ... } click to toggle source
# File lib/raygun.rb, line 69
def track_exceptions
  yield
rescue => e
  track_exception(e)
end

Private Class Methods

print_api_key_warning() click to toggle source
should_report?(exception) click to toggle source
# File lib/raygun.rb, line 163
def should_report?(exception)
  if configuration.silence_reporting
    log('skipping reporting because Configuration.silence_reporting is enabled')

    return false
  end

  if configuration.ignore.flatten.include?(exception.class.to_s)
    log("skipping reporting of exception #{exception.class} because it is in the ignore list")

    return false
  end

  true
end
track_exception_async(*args) click to toggle source
# File lib/raygun.rb, line 119
def track_exception_async(*args)
  future = Concurrent::Future.execute { track_exception_sync(*args) }
  future.add_observer(lambda do |_, value, reason|
    if value == nil || !value.responds_to?(:response) || value.response.code != "202"
      log("unexpected response from Raygun, could indicate error: #{value.inspect}")
    end
  end, :call)
end
track_exception_sync(exception_instance, env, user, retry_count) click to toggle source
# File lib/raygun.rb, line 128
def track_exception_sync(exception_instance, env, user, retry_count)
  if should_report?(exception_instance)
    log('attempting to send exception')
    resp = Client.new.track_exception(exception_instance, env, user)
    log('sent payload to api')

    resp
  end
rescue Exception => e
  log('error sending exception to raygun, see failsafe logger for more information')

  if configuration.failsafe_logger
    failsafe_log("Problem reporting exception to Raygun: #{e.class}: #{e.message}\n\n#{e.backtrace.join("\n")}")
  end

  if retry_count > 0
    new_exception = e.exception("raygun4ruby encountered an exception processing your exception")
    new_exception.set_backtrace(e.backtrace)

    env[:custom_data] ||= {}
    env[:custom_data].merge!(original_stacktrace: exception_instance.backtrace)

    ::Raygun::Breadcrumbs::Store.clear

    track_exception(new_exception, env, user, retry_count - 1)
  else
    raise e
  end
end