Sha256: 583ac643c0d831ca8c67a5950045a6d3d3e3c718aaee3353228338b5be52cb01

Contents?: true

Size: 1.67 KB

Versions: 2

Compression:

Stored size: 1.67 KB

Contents

require_relative '../patcher'
require_relative 'ext'

module Datadog
  module Tracing
    module Contrib
      module Aws
        # Patcher enables patching of 'aws' module.
        module Patcher
          include Contrib::Patcher

          module_function

          def target_version
            Integration.version
          end

          def patch
            require_relative 'parsed_context'
            require_relative 'instrumentation'
            require_relative 'services'

            add_plugin(Seahorse::Client::Base, *loaded_constants)

            # Special handling for S3 URL Presigning.
            # @see Datadog::Tracing::Contrib::Aws::S3Presigner
            ::Aws::S3::Presigner.prepend(S3Presigner) if defined?(::Aws::S3::Presigner)
          end

          def add_plugin(*targets)
            targets.each { |klass| klass.add_plugin(Instrumentation) }
          end

          def loaded_constants
            # Cross-check services against loaded AWS constants
            # Module#const_get can return a constant from ancestors when there's a miss.
            # If this conincidentally matches another constant, it will attempt to patch
            # the wrong constant, resulting in patch failure.
            available_services = ::Aws.constants & SERVICES.map(&:to_sym)

            available_services.each_with_object([]) do |service, constants|
              next if ::Aws.autoload?(service)

              constants << ::Aws.const_get(service, false).const_get(:Client, false) rescue next
            end
          end

          def get_option(option)
            Datadog.configuration.tracing[:aws].get_option(option)
          end
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ddtrace-1.10.1 lib/datadog/tracing/contrib/aws/patcher.rb
ddtrace-1.10.0 lib/datadog/tracing/contrib/aws/patcher.rb