Sha256: d0e9b1110119645e9508ac4e5cb1fa4fe9a5b0323c6d043700cfabf0be7f7197

Contents?: true

Size: 1.75 KB

Versions: 18

Compression:

Stored size: 1.75 KB

Contents

require 'ddtrace/ext/app_types'
require 'ddtrace/ext/net'
require 'ddtrace/ext/sql'
require 'ddtrace/contrib/analytics'
require 'ddtrace/contrib/mysql2/ext'

module Datadog
  module Contrib
    module Mysql2
      # Mysql2::Client patch module
      module Instrumentation
        def self.included(base)
          base.send(:prepend, InstanceMethods)
        end

        # Mysql2::Client patch instance methods
        module InstanceMethods
          def query(sql, options = {})
            datadog_pin.tracer.trace(Ext::SPAN_QUERY) do |span|
              span.resource = sql
              span.service = datadog_pin.service
              span.span_type = Datadog::Ext::SQL::TYPE

              # Set analytics sample rate
              Contrib::Analytics.set_sample_rate(span, analytics_sample_rate) if analytics_enabled?

              span.set_tag(Ext::TAG_DB_NAME, query_options[:database])
              span.set_tag(Datadog::Ext::NET::TARGET_HOST, query_options[:host])
              span.set_tag(Datadog::Ext::NET::TARGET_PORT, query_options[:port])
              super(sql, options)
            end
          end

          def datadog_pin
            @datadog_pin ||= Datadog::Pin.new(
              Datadog.configuration[:mysql2][:service_name],
              app: Ext::APP,
              app_type: Datadog::Ext::AppTypes::DB,
              tracer: Datadog.configuration[:mysql2][:tracer]
            )
          end

          private

          def datadog_configuration
            Datadog.configuration[:mysql2]
          end

          def analytics_enabled?
            datadog_configuration[:analytics_enabled]
          end

          def analytics_sample_rate
            datadog_configuration[:analytics_sample_rate]
          end
        end
      end
    end
  end
end

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
ddtrace-0.36.0 lib/ddtrace/contrib/mysql2/instrumentation.rb
ls-trace-0.1.2 lib/ddtrace/contrib/mysql2/instrumentation.rb
ddtrace-0.35.2 lib/ddtrace/contrib/mysql2/instrumentation.rb
ddtrace-0.35.1 lib/ddtrace/contrib/mysql2/instrumentation.rb
ddtrace-0.35.0 lib/ddtrace/contrib/mysql2/instrumentation.rb
ddtrace-0.34.2 lib/ddtrace/contrib/mysql2/instrumentation.rb
ddtrace-0.34.1 lib/ddtrace/contrib/mysql2/instrumentation.rb
ddtrace-0.34.0 lib/ddtrace/contrib/mysql2/instrumentation.rb
ddtrace-0.33.1 lib/ddtrace/contrib/mysql2/instrumentation.rb
ddtrace-0.33.0 lib/ddtrace/contrib/mysql2/instrumentation.rb
ddtrace-0.32.0 lib/ddtrace/contrib/mysql2/instrumentation.rb
ddtrace-0.31.1 lib/ddtrace/contrib/mysql2/instrumentation.rb
ddtrace-0.31.0 lib/ddtrace/contrib/mysql2/instrumentation.rb
ddtrace-0.30.1 lib/ddtrace/contrib/mysql2/instrumentation.rb
ddtrace-0.30.0 lib/ddtrace/contrib/mysql2/instrumentation.rb
ddtrace-0.29.1 lib/ddtrace/contrib/mysql2/instrumentation.rb
ls-trace-0.1.1 lib/ddtrace/contrib/mysql2/instrumentation.rb
ddtrace-0.29.0 lib/ddtrace/contrib/mysql2/instrumentation.rb