Class: Instana::Instrumentation::Lambda::Handler

Inherits:
Seahorse::Client::Handler
  • Object
show all
Defined in:
lib/instana/instrumentation/aws_sdk_lambda.rb

Instance Method Summary collapse

Instance Method Details

#call(context) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/instana/instrumentation/aws_sdk_lambda.rb', line 9

def call(context)
  return @handler.call(context) unless [:invoke_async, :invoke].include?(context.operation_name)

  if context.params[:client_context].nil? && ::Instana.tracer.tracing? && context.operation_name == :invoke
    span_context = ::Instana.tracer.context
    payload = {
      'X-INSTANA-T' => span_context.trace_id,
      'X-INSTANA-S' => span_context.span_id,
      'X-INSTANA-L' => span_context.level.to_s
    }

    context.params[:client_context] = Base64.strict_encode64(JSON.dump(payload))
  end

  tags = {
    function: context.params[:function_name],
    type: context.params[:invocation_type]
  }.reject { |_, v| v.nil? }

  ::Instana.tracer.in_span(:"aws.lambda.invoke", attributes: {aws: {lambda: {invoke: tags}}}) do
    response = @handler.call(context)
    if response.respond_to? :status_code
      ::Instana.tracer.log_info(:http => {:status => response.status_code })
    end
    response
  end
end