Sha256: 00800d1780b37f72619d64b1344fe3adb4bdca192b105e3444f361052c9ae9cf

Contents?: true

Size: 1.8 KB

Versions: 33

Compression:

Stored size: 1.8 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::Database
      module Database
        def self.included(base)
          base.send(:prepend, InstanceMethods)
        end

        # Instance methods for instrumenting Sequel::Database
        module InstanceMethods
          def run(sql, options = ::Sequel::OPTS)
            opts = parse_opts(sql, options)

            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(sql, options)
            end
            response
          end

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

          private

          def adapter_name
            Utils.adapter_name(self)
          end

          def parse_opts(sql, opts)
            db_opts = if ::Sequel::VERSION < '3.41.0' && self.class.to_s !~ /Dataset$/
                        @opts
                      elsif instance_variable_defined?(:@pool) && @pool
                        @pool.db.opts
                      end
            Utils.parse_opts(sql, opts, db_opts)
          end
        end
      end
    end
  end
end

Version data entries

33 entries across 33 versions & 2 rubygems

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