Method: ScoutRailsProxy::Instruments::ActiveRecordInstruments#scout_ar_metric_name

Defined in:
lib/scout_rails_proxy/instruments/active_record_instruments.rb

#scout_ar_metric_name(sql, name) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/scout_rails_proxy/instruments/active_record_instruments.rb', line 23

def scout_ar_metric_name(sql,name)
  if name && (parts = name.split " ") && parts.size == 2
    model = parts.first
    operation = parts.last.downcase
    metric_name = case operation
                  when 'load' then 'find'
                  when 'indexes', 'columns' then nil # not under developer control
                  when 'destroy', 'find', 'save', 'create' then operation
                  when 'update' then 'save'
                  else
                    if model == 'Join'
                      operation
                    end
                  end
    metric = "ActiveRecord/#{model}/#{metric_name}" if metric_name
    metric = "ActiveRecord/SQL/other" if metric.nil?
  else
    metric = "ActiveRecord/SQL/Unknown"
  end
  metric
end