Module: NewRelic::Agent::Instrumentation::DataMapperInstrumentation
- Defined in:
- lib/new_relic/agent/instrumentation/data_mapper.rb
Instance Method Summary collapse
-
#log(msg) ⇒ Object
Unlike in AR, log is called in DM after the query actually ran, complete with metrics.
Instance Method Details
#log(msg) ⇒ Object
Unlike in AR, log is called in DM after the query actually ran, complete with metrics. Since DO has already calculated the duration, there’s nothing more to measure, so just record and log.
We rely on the assumption that all possible entry points have been hooked with tracers, ensuring that notice_sql attaches this SQL to the proper call scope.
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 |
# File 'lib/new_relic/agent/instrumentation/data_mapper.rb', line 190 def log(msg) return unless NewRelic::Agent.is_execution_traced? return unless operation = case NewRelic::Helper.correctly_encoded(msg.query) when /^\s*select/i then 'find' when /^\s*(update|insert)/i then 'save' when /^\s*delete/i then 'destroy' else nil end # FYI: self.to_s will yield connection URI string. duration = msg.duration / 1000000.0 # Attach SQL to current segment/scope. NewRelic::Agent.instance.transaction_sampler.notice_sql(msg.query, nil, duration) # Record query duration associated with each of the desired metrics. metrics = [ "ActiveRecord/#{operation}", 'ActiveRecord/all' ] metrics.each do |metric| NewRelic::Agent.instance.stats_engine.get_stats_no_scope(metric).trace_call(duration) end ensure super end |