module Sequel::MmtrixInstrumentation

Mmtrix’s Sequel instrumentation is implemented via a plugin for Sequel::Models, and an extension for Sequel::Databases. Every database handle that Sequel knows about when Mmtrix is loaded will automatically be instrumented, but if you’re using a version of Sequel before 3.47.0, you’ll need to add the extension yourself if you create any after the instrumentation is loaded:

db = Sequel.connect( ... )
db.extension :mmtrix_instrumentation

Versions 3.47.0 and later use ‘Database.extension` to automatically install the extension for new connections.

Disabling

If you don’t want your models or database connections to be instrumented, you can disable them by setting ‘disable_database_instrumentation` in your `mmtrix.yml` to `true`. It will also honor the `disable_activerecord_instrumentation` setting.

Constants

THREAD_SAFE_CONNECTION_POOL_CLASSES

Public Instance Methods

log_yield(sql, args=nil) click to toggle source

Instrument all queries that go through execute_query.

Calls superclass method
# File lib/sequel/extensions/mmtrix_instrumentation.rb, line 35
def log_yield(sql, args=nil) #THREAD_LOCAL_ACCESS
  rval = nil
  product = Mmtrix::Agent::Instrumentation::SequelHelper.product_name_from_adapter(self.class.adapter_scheme)
  metrics = Mmtrix::Agent::Datastores::MetricHelper.metrics_from_sql(product, sql)
  scoped_metric = metrics.first

  Mmtrix::Agent::MethodTracer.trace_execution_scoped(metrics) do
    t0 = Time.now
    begin
      rval = super
    ensure
      notice_sql(sql, scoped_metric, args, t0, Time.now)
    end
  end

  return rval
end
notice_sql(sql, metric_name, args, start, finish) click to toggle source
# File lib/sequel/extensions/mmtrix_instrumentation.rb, line 57
def notice_sql(sql, metric_name, args, start, finish)
  state    = Mmtrix::Agent::TransactionState.tl_get
  duration = finish - start

  explainer = Proc.new do |*|
    if THREAD_SAFE_CONNECTION_POOL_CLASSES.include?(self.pool.class)
      self[ sql ].explain
    else
      Mmtrix::Agent.logger.log_once(:info, :sequel_explain_skipped, "Not running SQL explains because Sequel is not in recognized multi-threaded mode")
      nil
    end
  end
  Mmtrix::Agent.instance.transaction_sampler.notice_sql(sql, self.opts, duration, state, explainer)
  Mmtrix::Agent.instance.sql_sampler.notice_sql(sql, metric_name, self.opts, duration, state, explainer)
end