Sha256: ff72920a109b63716189bf645f230c53973772f77f6483252a07b5bb404a2a0c

Contents?: true

Size: 1.98 KB

Versions: 7

Compression:

Stored size: 1.98 KB

Contents

require 'ddtrace/contrib/analytics'
require 'ddtrace/contrib/aws/ext'
require 'ddtrace/ext/http'
require 'ddtrace/ext/integration'

module Datadog
  module Contrib
    module Aws
      # A Seahorse::Client::Plugin that enables instrumentation for all AWS services
      class Instrumentation < Seahorse::Client::Plugin
        def add_handlers(handlers, _)
          handlers.add(Handler, step: :validate)
        end
      end

      # Generates Spans for all interactions with AWS
      class Handler < Seahorse::Client::Handler
        def call(context)
          tracer.trace(Ext::SPAN_COMMAND) do |span|
            @handler.call(context).tap do
              annotate!(span, ParsedContext.new(context))
            end
          end
        end

        private

        def annotate!(span, context)
          span.service = configuration[:service_name]
          span.span_type = Datadog::Ext::HTTP::TYPE_OUTBOUND
          span.name = Ext::SPAN_COMMAND
          span.resource = context.safely(:resource)

          # Tag as an external peer service
          span.set_tag(Datadog::Ext::Integration::TAG_PEER_SERVICE, span.service)

          # Set analytics sample rate
          if Contrib::Analytics.enabled?(configuration[:analytics_enabled])
            Contrib::Analytics.set_sample_rate(span, configuration[:analytics_sample_rate])
          end

          span.set_tag(Ext::TAG_AGENT, Ext::TAG_DEFAULT_AGENT)
          span.set_tag(Ext::TAG_OPERATION, context.safely(:operation))
          span.set_tag(Ext::TAG_REGION, context.safely(:region))
          span.set_tag(Ext::TAG_PATH, context.safely(:path))
          span.set_tag(Ext::TAG_HOST, context.safely(:host))
          span.set_tag(Datadog::Ext::HTTP::METHOD, context.safely(:http_method))
          span.set_tag(Datadog::Ext::HTTP::STATUS_CODE, context.safely(:status_code))
        end

        def tracer
          configuration[:tracer]
        end

        def configuration
          Datadog.configuration[:aws]
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
ddtrace-0.49.0 lib/ddtrace/contrib/aws/instrumentation.rb
ddtrace-0.48.0 lib/ddtrace/contrib/aws/instrumentation.rb
ddtrace-0.47.0 lib/ddtrace/contrib/aws/instrumentation.rb
ddtrace-0.46.0 lib/ddtrace/contrib/aws/instrumentation.rb
ddtrace-0.45.0 lib/ddtrace/contrib/aws/instrumentation.rb
ddtrace-0.44.0 lib/ddtrace/contrib/aws/instrumentation.rb
ddtrace-0.43.0 lib/ddtrace/contrib/aws/instrumentation.rb