Sha256: f44472d9871a11eb3503543418b198d9a091828367f5a7417d35c2726e050c97

Contents?: true

Size: 1.9 KB

Versions: 38

Compression:

Stored size: 1.9 KB

Contents

require 'ddtrace/ext/sql'
require 'ddtrace/ext/app_types'
require 'ddtrace/contrib/analytics'
require 'ddtrace/contrib/sequel/ext'
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(Ext::SPAN_QUERY) do |span|
              span.service = datadog_pin.service
              span.resource = opts[:query]
              span.span_type = Datadog::Ext::SQL::TYPE
              Utils.set_analytics_sample_rate(span)
              span.set_tag(Ext::TAG_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

38 entries across 38 versions & 2 rubygems

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