Sha256: 0fb58e7ca5400501a690fbddc3baa8f243adb1d5b78c530c620cae1a0f9db57c

Contents?: true

Size: 1.89 KB

Versions: 32

Compression:

Stored size: 1.89 KB

Contents

require 'sinatra/base'
require 'honeybadger/ruby'

module Honeybadger
  module Init
    module Sinatra
      ::Sinatra::Base.class_eval do
        class << self
          def build_with_honeybadger(*args, &block)
            configure_honeybadger
            install_honeybadger
            # Sinatra is a special case. Sinatra starts the web application in an at_exit
            # handler. And, since we require sinatra before requiring HB, the only way to
            # setup our at_exit callback is in the sinatra build callback honeybadger/init/sinatra.rb
            Honeybadger.install_at_exit_callback
            build_without_honeybadger(*args, &block)
          end
          alias :build_without_honeybadger :build
          alias :build :build_with_honeybadger

          def configure_honeybadger
            return unless defined?(honeybadger_api_key)
            Honeybadger.configure do |config|
              config.api_key = honeybadger_api_key
            end
          end

          def install_honeybadger
            config = Honeybadger.config
            return unless config[:'sinatra.enabled']
            if config[:'exceptions.enabled']
              # These two must come before the ErrorNotifier, since an error/response
              # passes through middleware from inner to outer (bottom to top)
              install_honeybadger_middleware(Honeybadger::Rack::UserFeedback)
              install_honeybadger_middleware(Honeybadger::Rack::UserInformer)
              install_honeybadger_middleware(Honeybadger::Rack::ErrorNotifier)
            end
          end

          def install_honeybadger_middleware(klass)
            return if middleware.any? {|m| m[0] == klass }
            use(klass)
          end

        end
      end
    end
  end
end

Honeybadger.init!({
  env: ENV['APP_ENV'] || ENV['RACK_ENV'],
  framework: :sinatra,
  :'logging.path' => 'STDOUT'
})

Honeybadger.load_plugins!

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
honeybadger-5.19.1 lib/honeybadger/init/sinatra.rb
honeybadger-5.19.0 lib/honeybadger/init/sinatra.rb
honeybadger-5.18.0 lib/honeybadger/init/sinatra.rb
honeybadger-5.17.0 lib/honeybadger/init/sinatra.rb
honeybadger-5.16.0 lib/honeybadger/init/sinatra.rb
honeybadger-5.15.6 lib/honeybadger/init/sinatra.rb
honeybadger-5.15.5 lib/honeybadger/init/sinatra.rb
honeybadger-5.15.4 lib/honeybadger/init/sinatra.rb
honeybadger-5.15.3 lib/honeybadger/init/sinatra.rb
honeybadger-5.15.2 lib/honeybadger/init/sinatra.rb
honeybadger-5.15.1 lib/honeybadger/init/sinatra.rb
honeybadger-5.15.0 lib/honeybadger/init/sinatra.rb
honeybadger-5.14.2 lib/honeybadger/init/sinatra.rb
honeybadger-5.14.1 lib/honeybadger/init/sinatra.rb
honeybadger-5.14.0 lib/honeybadger/init/sinatra.rb
honeybadger-5.13.3 lib/honeybadger/init/sinatra.rb
honeybadger-5.13.2 lib/honeybadger/init/sinatra.rb
honeybadger-5.13.1 lib/honeybadger/init/sinatra.rb
honeybadger-5.13.0 lib/honeybadger/init/sinatra.rb
honeybadger-5.12.0 lib/honeybadger/init/sinatra.rb