Sha256: dd9bc151251c2c6f55c608e6bbc7820a555b08ac07270aee1defea61952563f0

Contents?: true

Size: 1.61 KB

Versions: 23

Compression:

Stored size: 1.61 KB

Contents

require 'ddtrace/ext/net'
require 'ddtrace/contrib/analytics'
require 'ddtrace/contrib/dalli/ext'
require 'ddtrace/contrib/dalli/quantize'

module Datadog
  module Contrib
    module Dalli
      # Instruments every interaction with the memcached server
      module Instrumentation
        def self.included(base)
          base.send(:prepend, InstanceMethods)
        end

        # InstanceMethods - implementing instrumentation
        module InstanceMethods
          def request(op, *args)
            tracer.trace(Datadog::Contrib::Dalli::Ext::SPAN_COMMAND) do |span|
              span.resource = op.to_s.upcase
              span.service = datadog_configuration[:service_name]
              span.span_type = Datadog::Contrib::Dalli::Ext::SPAN_TYPE_COMMAND

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

              span.set_tag(Datadog::Ext::NET::TARGET_HOST, hostname)
              span.set_tag(Datadog::Ext::NET::TARGET_PORT, port)
              cmd = Datadog::Contrib::Dalli::Quantize.format_command(op, args)
              span.set_tag(Datadog::Contrib::Dalli::Ext::TAG_COMMAND, cmd)

              super
            end
          end

          private

          def tracer
            datadog_configuration[:tracer]
          end

          def datadog_configuration
            Datadog.configuration[:dalli, "#{hostname}:#{port}"] || Datadog.configuration[:dalli]
          end
        end
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 2 rubygems

Version Path
ls-trace-0.2.0 lib/ddtrace/contrib/dalli/instrumentation.rb
ddtrace-0.40.0 lib/ddtrace/contrib/dalli/instrumentation.rb
ddtrace-0.39.0 lib/ddtrace/contrib/dalli/instrumentation.rb
ddtrace-0.38.0 lib/ddtrace/contrib/dalli/instrumentation.rb
ddtrace-0.37.0 lib/ddtrace/contrib/dalli/instrumentation.rb
ddtrace-0.36.0 lib/ddtrace/contrib/dalli/instrumentation.rb
ls-trace-0.1.2 lib/ddtrace/contrib/dalli/instrumentation.rb
ddtrace-0.35.2 lib/ddtrace/contrib/dalli/instrumentation.rb
ddtrace-0.35.1 lib/ddtrace/contrib/dalli/instrumentation.rb
ddtrace-0.35.0 lib/ddtrace/contrib/dalli/instrumentation.rb
ddtrace-0.34.2 lib/ddtrace/contrib/dalli/instrumentation.rb
ddtrace-0.34.1 lib/ddtrace/contrib/dalli/instrumentation.rb
ddtrace-0.34.0 lib/ddtrace/contrib/dalli/instrumentation.rb
ddtrace-0.33.1 lib/ddtrace/contrib/dalli/instrumentation.rb
ddtrace-0.33.0 lib/ddtrace/contrib/dalli/instrumentation.rb
ddtrace-0.32.0 lib/ddtrace/contrib/dalli/instrumentation.rb
ddtrace-0.31.1 lib/ddtrace/contrib/dalli/instrumentation.rb
ddtrace-0.31.0 lib/ddtrace/contrib/dalli/instrumentation.rb
ddtrace-0.30.1 lib/ddtrace/contrib/dalli/instrumentation.rb
ddtrace-0.30.0 lib/ddtrace/contrib/dalli/instrumentation.rb