Module: ScoutApm::Instruments::ActiveRecordInstruments
- Defined in:
- lib/scout_apm/instruments/active_record.rb
Overview
Contains ActiveRecord instrument, aliasing ActiveRecord::ConnectionAdapters::AbstractAdapter#log calls to trace calls to the database.
Class Method Summary collapse
Instance Method Summary collapse
-
#log_with_scout_instruments(*args, &block) ⇒ Object
self.included.
- #scout_ar_metric_name(sql, name) ⇒ Object
Class Method Details
.included(instrumented_class) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/scout_apm/instruments/active_record.rb', line 48 def self.included(instrumented_class) ScoutApm::Agent.instance.logger.info "Instrumenting #{instrumented_class.inspect}" instrumented_class.class_eval do unless instrumented_class.method_defined?(:log_without_scout_instruments) alias_method :log_without_scout_instruments, :log alias_method :log, :log_with_scout_instruments protected :log end end end |
Instance Method Details
#log_with_scout_instruments(*args, &block) ⇒ Object
self.included
59 60 61 62 63 64 |
# File 'lib/scout_apm/instruments/active_record.rb', line 59 def log_with_scout_instruments(*args, &block) sql, name = args self.class.instrument(scout_ar_metric_name(sql,name), :desc => Utils::SqlSanitizer.new(sql).to_s) do log_without_scout_instruments(sql, name, &block) end end |
#scout_ar_metric_name(sql, name) ⇒ Object
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/scout_apm/instruments/active_record.rb', line 66 def scout_ar_metric_name(sql,name) # sql: SELECT "places".* FROM "places" ORDER BY "places"."position" ASC # name: Place Load 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', 'exists' 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 |