Module: NewRelic::Agent::Instrumentation::SequelInstrumentation

Defined in:
lib/newrelic_sequel/sequel.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



68
69
70
71
72
73
# File 'lib/newrelic_sequel/sequel.rb', line 68

def self.included(klass)
  klass.class_eval do
    alias_method :log_duration_without_newrelic_instrumentation, :log_duration
    alias_method :log_duration, :log_duration_with_newrelic_instrumentation
  end
end

Instance Method Details

#log_duration_with_newrelic_instrumentation(duration, sql) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/newrelic_sequel/sequel.rb', line 75

def log_duration_with_newrelic_instrumentation(duration, sql)
  return unless NewRelic::Agent.is_execution_traced?
  return unless operation = case sql
                              when /^\s*select/i then
                                'find'
                              when /^\s*(update|insert)/i then
                                'save'
                              when /^\s*delete/i then
                                'destroy'
                              else
                                nil
                            end

  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
ensure
  log_duration_without_newrelic_instrumentation(duration, sql)
end