Sha256: 1810322499697f509efbbca7bc91afc08aedfb0c27f17f2b51bd83ca216df6e0

Contents?: true

Size: 1.77 KB

Versions: 17

Compression:

Stored size: 1.77 KB

Contents

require 'ddtrace/ext/sql'
require 'ddtrace/ext/app_types'
require 'ddtrace/contrib/sequel/utils'

module Datadog
  module Contrib
    module Sequel
      # Adds instrumentation to Sequel::Dataset
      module Dataset
        def self.included(base)
          base.send(:prepend, InstanceMethods)
        end

        # Instance methods for instrumenting Sequel::Dataset
        module InstanceMethods
          def execute(sql, options = ::Sequel::OPTS, &block)
            trace_execute(proc { super(sql, options, &block) }, sql, options, &block)
          end

          def execute_ddl(sql, options = ::Sequel::OPTS, &block)
            trace_execute(proc { super(sql, options, &block) }, sql, options, &block)
          end

          def execute_dui(sql, options = ::Sequel::OPTS, &block)
            trace_execute(proc { super(sql, options, &block) }, sql, options, &block)
          end

          def execute_insert(sql, options = ::Sequel::OPTS, &block)
            trace_execute(proc { super(sql, options, &block) }, sql, options, &block)
          end

          def datadog_pin
            Datadog::Pin.get_from(db)
          end

          private

          def trace_execute(super_method, sql, options, &block)
            opts = Utils.parse_opts(sql, options, db.opts)
            response = nil

            datadog_pin.tracer.trace('sequel.query') do |span|
              span.service = datadog_pin.service
              span.resource = opts[:query]
              span.span_type = Datadog::Ext::SQL::TYPE
              span.set_tag('sequel.db.vendor', adapter_name)
              response = super_method.call(sql, options, &block)
            end
            response
          end

          def adapter_name
            Utils.adapter_name(db)
          end
        end
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
ddtrace-0.16.1 lib/ddtrace/contrib/sequel/dataset.rb
ddtrace-0.15.0.internaltracinfeature1 lib/ddtrace/contrib/sequel/dataset.rb
ddtrace-0.16.0 lib/ddtrace/contrib/sequel/dataset.rb
ddtrace-0.14.2.disableprotocolversion4 lib/ddtrace/contrib/sequel/dataset.rb
ddtrace-0.15.0 lib/ddtrace/contrib/sequel/dataset.rb
ddtrace-0.14.2.withoutpriorityparsing1 lib/ddtrace/contrib/sequel/dataset.rb
ddtrace-0.14.2 lib/ddtrace/contrib/sequel/dataset.rb
ddtrace-0.14.1 lib/ddtrace/contrib/sequel/dataset.rb
ddtrace-0.15.0.beta1 lib/ddtrace/contrib/sequel/dataset.rb
ddtrace-0.14.0 lib/ddtrace/contrib/sequel/dataset.rb
ddtrace-0.14.0.rc1 lib/ddtrace/contrib/sequel/dataset.rb
ddtrace-0.13.2 lib/ddtrace/contrib/sequel/dataset.rb
ddtrace-0.14.0.beta2 lib/ddtrace/contrib/sequel/dataset.rb
ddtrace-0.14.0.beta1 lib/ddtrace/contrib/sequel/dataset.rb
ddtrace-0.13.1 lib/ddtrace/contrib/sequel/dataset.rb
ddtrace-0.13.0 lib/ddtrace/contrib/sequel/dataset.rb
ddtrace-0.13.0.beta1 lib/ddtrace/contrib/sequel/dataset.rb