Module: ScoutApm::Instruments::ActiveRecordRelationQueryInstruments

Defined in:
lib/scout_apm/instruments/active_record.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(instrumented_class) ⇒ Object



314
315
316
317
318
319
320
321
322
# File 'lib/scout_apm/instruments/active_record.rb', line 314

def self.included(instrumented_class)
  ScoutApm::Agent.instance.context.logger.info "Instrumenting ActiveRecord::Relation#exec_queries - #{instrumented_class.inspect}"
  instrumented_class.class_eval do
    unless instrumented_class.method_defined?(:exec_queries_without_scout_instruments)
      alias_method :exec_queries_without_scout_instruments, :exec_queries
      alias_method :exec_queries, :exec_queries_with_scout_instruments
    end
  end
end

.prepended(instrumented_class) ⇒ Object



310
311
312
# File 'lib/scout_apm/instruments/active_record.rb', line 310

def self.prepended(instrumented_class)
  ScoutApm::Agent.instance.context.logger.info "Instrumenting ActiveRecord::Relation#exec_queries - #{instrumented_class.inspect} (prepending)"
end

Instance Method Details

#exec_queries(*args, &block) ⇒ Object Also known as: exec_queries_with_scout_instruments



324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
# File 'lib/scout_apm/instruments/active_record.rb', line 324

def exec_queries(*args, &block)
  req = ScoutApm::RequestManager.lookup
  layer = ScoutApm::Layer.new("ActiveRecord", Utils::ActiveRecordMetricName::DEFAULT_METRIC)
  layer.annotate_layer(:ignorable => true)
  layer.desc = SqlList.new
  req.start_layer(layer)
  req.ignore_children!
  begin
    if ScoutApm::Environment.instance.supports_module_prepend?
      super(*args, &block)
    else
      exec_queries_without_scout_instruments(*args, &block)
    end
  ensure
    req.acknowledge_children!
    req.stop_layer
  end
end