Module: ScoutApm::Instruments::ActiveRecordRelationInstruments

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(instrumented_class) ⇒ Object



446
447
448
449
450
451
452
453
454
455
456
457
# File 'lib/scout_apm/instruments/active_record.rb', line 446

def self.included(instrumented_class)
  ::ActiveRecord::Relation.class_eval do
    alias_method :update_all_without_scout_instruments, :update_all
    alias_method :update_all, :update_all_with_scout_instruments

    alias_method :delete_all_without_scout_instruments, :delete_all
    alias_method :delete_all, :delete_all_with_scout_instruments

    alias_method :destroy_all_without_scout_instruments, :destroy_all
    alias_method :destroy_all, :destroy_all_with_scout_instruments
  end
end

Instance Method Details

#delete_all_with_scout_instruments(*args, &block) ⇒ Object



474
475
476
477
478
479
480
481
482
483
484
485
486
487
# File 'lib/scout_apm/instruments/active_record.rb', line 474

def delete_all_with_scout_instruments(*args, &block)
  model = self.name

  req = ScoutApm::RequestManager.lookup
  layer = ScoutApm::Layer.new("ActiveRecord", Utils::ActiveRecordMetricName.new("", "#{model} Delete"))
  req.start_layer(layer)
  req.ignore_children!
  begin
    delete_all_without_scout_instruments(*args, &block)
  ensure
    req.acknowledge_children!
    req.stop_layer
  end
end

#destroy_all_with_scout_instruments(*args, &block) ⇒ Object



489
490
491
492
493
494
495
496
497
498
499
500
501
502
# File 'lib/scout_apm/instruments/active_record.rb', line 489

def destroy_all_with_scout_instruments(*args, &block)
  model = self.name

  req = ScoutApm::RequestManager.lookup
  layer = ScoutApm::Layer.new("ActiveRecord", Utils::ActiveRecordMetricName.new("", "#{model} Delete"))
  req.start_layer(layer)
  req.ignore_children!
  begin
    destroy_all_without_scout_instruments(*args, &block)
  ensure
    req.acknowledge_children!
    req.stop_layer
  end
end

#update_all_with_scout_instruments(*args, &block) ⇒ Object



459
460
461
462
463
464
465
466
467
468
469
470
471
472
# File 'lib/scout_apm/instruments/active_record.rb', line 459

def update_all_with_scout_instruments(*args, &block)
  model = self.name

  req = ScoutApm::RequestManager.lookup
  layer = ScoutApm::Layer.new("ActiveRecord", Utils::ActiveRecordMetricName.new("", "#{model} Update"))
  req.start_layer(layer)
  req.ignore_children!
  begin
    update_all_without_scout_instruments(*args, &block)
  ensure
    req.acknowledge_children!
    req.stop_layer
  end
end