Module: NewRelic::Agent::Instrumentation::SequelDurationRecorder
- Defined in:
- lib/newrelic_sequel/sequel.rb
Class Method Summary collapse
Class Method Details
.extract_operation_from_sql(sql) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/newrelic_sequel/sequel.rb', line 80 def self.extract_operation_from_sql(sql) case sql[0...15] when /^\s*select/i then 'find' when /^\s*(update|insert)/i then 'save' when /^\s*delete/i then 'destroy' when /^\s*with (?:recursive)?/i then # Recursive queries for Postgresql # Syntax is: WITH [RECURSIVE] # The results can be used to select/update/delete rows # we're always tracking it as select here, because finding what the # "real" action is, probably require a full SQL parser. 'find' else nil end end |
.record(duration, sql) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/newrelic_sequel/sequel.rb', line 68 def self.record(duration, sql) return unless NewRelic::Agent.is_execution_traced? return unless operation = extract_operation_from_sql(sql) NewRelic::Agent.instance.transaction_sampler.notice_sql(sql, nil, duration) metrics = ["ActiveRecord/#{operation}", 'ActiveRecord/all'] metrics.each do |metric| NewRelic::Agent.instance.stats_engine.get_stats_no_scope(metric).trace_call(duration) end end |