module Honeybadger::Plugins::LambdaExtension

Public Instance Methods

hb_wrap_handler(*handler_names) click to toggle source

Wrap Lambda handlers so exceptions can be automatically captured

Usage:

# Automatically included in the top-level main object hb_wrap_handler :my_handler_1, :my_handler_2

def my_handler_1(event:, context:) end

class MyLambdaApp extend ::Honeybadger::Plugins::LambdaExtension

hb_wrap_handler :my_handler_1, :my_handler_2

def self.my_handler_1(event:, context:)
end

end

Calls superclass method
# File lib/honeybadger/plugins/lambda.rb, line 25
def hb_wrap_handler(*handler_names)
  mod = Module.new do
    handler_names.each do |handler|
      define_method(handler) do |event:, context:|
        begin
          Honeybadger.context(aws_request_id: context.aws_request_id) if context.respond_to?(:aws_request_id)

          super(event: event, context: context)
        rescue => e
          Honeybadger.notify(e)
          raise
        end
      end
    end
  end

  self.singleton_class.prepend(mod)
  Kernel.singleton_class.prepend(mod) if self == TOPLEVEL_BINDING.eval("self")
end