module Honeybadger

Honeybadger's public API is made up of two parts: the {Honeybadger} singleton module, and the {Agent} class. The singleton module delegates its methods to a global agent instance, {Agent#instance}; this allows methods to be accessed directly, for example when calling Honeybadger.notify:

begin
  raise 'testing an error report'
rescue => err
  Honeybadger.notify(err)
end

Custom agents may also be created by users who want to report to multiple Honeybadger projects in the same app (or have fine-grained control over configuration), however most users will use the global agent.

@see Honeybadger::Agent

Constants

BINDING_HAS_SOURCE_LOCATION

@api private Binding#source_location was added in Ruby 2.6.

GEM_ROOT

@api private Substitution for gem root in backtrace lines.

MAX_EXCEPTION_CAUSES

@api private

NOTIFIER

@api private

NOT_BLANK

@api private A Regexp which matches non-blank characters.

PROJECT_ROOT

@api private Substitution for project root in backtrace lines.

RELATIVE_ROOT

@api private Matches lines beginning with ./

STRING_EMPTY

@api private Empty String (used for equality comparisons and assignment).

VERSION

The current String Honeybadger version.

Public Instance Methods

install_at_exit_callback() click to toggle source

@api private

# File lib/honeybadger/singleton.rb, line 69
def install_at_exit_callback
  at_exit do
    if $! && !ignored_exception?($!) && Honeybadger.config[:'exceptions.notify_at_exit']
      Honeybadger.notify($!, component: 'at_exit', sync: true)
    end

    Honeybadger.stop if Honeybadger.config[:'send_data_at_exit']
  end
end
load_plugins!() click to toggle source

@api private

# File lib/honeybadger/singleton.rb, line 61
def load_plugins!
  Dir[File.expand_path('../plugins/*.rb', __FILE__)].each do |plugin|
    require plugin
  end
  Plugin.load!(self.config)
end
notify(exception_or_opts, opts = {}) click to toggle source

@!method notify(…) Forwards to {Agent.instance}. @see Agent#notify

# File lib/honeybadger/singleton.rb, line 54
def notify(exception_or_opts, opts = {})
  # Note this is defined directly (instead of via forwardable) so that
  # generated stack traces work as expected.
  Agent.instance.notify(exception_or_opts, opts)
end
start(config = {}) click to toggle source

@deprecated

# File lib/honeybadger/singleton.rb, line 80
  def start(config = {})
    raise NoMethodError, <<-WARNING
`Honeybadger.start` is no longer necessary and has been removed.

  Use `Honeybadger.configure` to explicitly configure the agent from Ruby moving forward:

  Honeybadger.configure do |config|
    config.api_key = 'project api key'
    config.exceptions.ignore += [CustomError]
  end
WARNING
  end

Private Instance Methods

ignored_exception?(exception) click to toggle source

@api private

# File lib/honeybadger/singleton.rb, line 95
def ignored_exception?(exception)
  exception.is_a?(SystemExit) ||
    ( exception.is_a?(SignalException) &&
       ( (exception.respond_to?(:signm) && exception.signm == "SIGTERM") ||
        # jruby has a missing #signm implementation
        ["TERM", "SIGTERM"].include?(exception.to_s) )
  )
end