Module: Honeybadger::Plugins::LambdaExtension Private

Defined in:
lib/honeybadger/plugins/lambda.rb

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Instance Method Summary collapse

Instance Method Details

#hb_wrap_handler(*handler_names) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# 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