Module: AWS

Defined in:
lib/stackify_ruby_apm_lambda.rb

Class Method Summary collapse

Class Method Details

.handler(event:, context:, &block) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/stackify_ruby_apm_lambda.rb', line 12

def self.handler(event:, context:, &block)
  begin
    ctx = StackifyRubyAPM::Context.new
    ctx.add_aws_context({:arn => context.invoked_function_arn})
    transaction = StackifyRubyAPM.transaction context.function_name, 'TASK', context: ctx
    ret = block.call
  rescue StackifyRubyAPM::InternalError
    raise # Don't report StackifyRubyAPM errors
  rescue StandardError => e
    StackifyRubyAPM.report e
    raise e
  ensure
    transaction.submit()
  end
  ret
end

.instrumentObject



4
5
6
7
8
9
10
# File 'lib/stackify_ruby_apm_lambda.rb', line 4

def self.instrument
  config = {
    transport: 'logging',
    queue: false,
  }
  StackifyRubyAPM.start config
end

.stackify_handler(event:, context:) ⇒ Object

STACKIFY LAMBDA HANDLER

Returns:

  • original function execution



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/stackify_ruby_apm_lambda.rb', line 32

def self.stackify_handler(event:, context:)
  begin
    if !StackifyRubyAPM.running?
      config = {
        transport: 'logging',
        queue: false,
      }
      StackifyRubyAPM.start config
    end

    ctx = StackifyRubyAPM::Context.new
    ctx.add_aws_context({:arn => context.invoked_function_arn})
    transaction = StackifyRubyAPM.transaction context.function_name, 'TASK', context: ctx

    lambda_handler = StackifyRubyAPM.agent.config.lambda_handler.split('.')
    function_file = lambda_handler[0]
    function_name = lambda_handler[-1]

    require "./#{function_file}"

    send(function_name, event: event, context: context)
  rescue StackifyRubyAPM::InternalError
    raise # Don't report StackifyRubyAPM errors
  rescue StandardError => e
    StackifyRubyAPM.report e
    raise e
  ensure
    transaction.submit()
  end
end