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



435
436
437
438
439
440
441
442
443
444
445
446
# File 'lib/scout_apm/instruments/active_record.rb', line 435

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



463
464
465
466
467
468
469
470
471
472
473
474
475
476
# File 'lib/scout_apm/instruments/active_record.rb', line 463

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



478
479
480
481
482
483
484
485
486
487
488
489
490
491
# File 'lib/scout_apm/instruments/active_record.rb', line 478

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



448
449
450
451
452
453
454
455
456
457
458
459
460
461
# File 'lib/scout_apm/instruments/active_record.rb', line 448

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