Sha256: 501ae2e5974e12c807affa879f6a9bbdda395c460ca728815782a639d9a5da23

Contents?: true

Size: 1.43 KB

Versions: 14

Compression:

Stored size: 1.43 KB

Contents

# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2021
require 'base64'

module Instana
  module Instrumentation
    class Lambda < Seahorse::Client::Plugin
      class Handler < Seahorse::Client::Handler
        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.start_or_continue_trace(:"aws.lambda.invoke", {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
      end

      def add_handlers(handlers, _config)
        handlers.add(Handler, step: :initialize)
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
instana-1.217.1 lib/instana/instrumentation/aws_sdk_lambda.rb
instana-1.217.0 lib/instana/instrumentation/aws_sdk_lambda.rb
instana-1.216.0 lib/instana/instrumentation/aws_sdk_lambda.rb
instana-1.215.1 lib/instana/instrumentation/aws_sdk_lambda.rb
instana-1.215.0 lib/instana/instrumentation/aws_sdk_lambda.rb
instana-1.214.4 lib/instana/instrumentation/aws_sdk_lambda.rb
instana-1.214.3 lib/instana/instrumentation/aws_sdk_lambda.rb
instana-1.214.2 lib/instana/instrumentation/aws_sdk_lambda.rb
instana-1.214.1 lib/instana/instrumentation/aws_sdk_lambda.rb
instana-1.214.0 lib/instana/instrumentation/aws_sdk_lambda.rb
instana-1.213.3 lib/instana/instrumentation/aws_sdk_lambda.rb
instana-1.213.2 lib/instana/instrumentation/aws_sdk_lambda.rb
instana-1.213.1 lib/instana/instrumentation/aws_sdk_lambda.rb
instana-1.213.0 lib/instana/instrumentation/aws_sdk_lambda.rb