Top Level Namespace

Defined Under Namespace

Modules: ActsAsSolr, NewRelic

Class Method Summary collapse

Class Method Details

.instrument_method(the_class, method_name) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/new_relic/agent/instrumentation/memcache.rb', line 8

def self.instrument_method(the_class, method_name)
    return unless the_class.method_defined? method_name.to_sym
    the_class.class_eval <<-EOD
  def #{method_name}_with_newrelic_trace(*args)
    metrics = ["MemCache/#{method_name}",
               (NewRelic::Agent::Instrumentation::MetricFrame.recording_web_transaction? ? 'MemCache/allWeb' : 'MemCache/allOther')]
    self.class.trace_execution_scoped(metrics) do
      t0 = Time.now
      begin
        #{method_name}_without_newrelic_trace(*args)
      ensure
        #{memcache_key_snippet(method_name)}
      end
    end
  end
  alias #{method_name}_without_newrelic_trace #{method_name}
  alias #{method_name} #{method_name}_with_newrelic_trace
    EOD
end

.memcache_key_snippet(method_name) ⇒ Object



28
29
30
31
# File 'lib/new_relic/agent/instrumentation/memcache.rb', line 28

def self.memcache_key_snippet(method_name)
  return "" unless NewRelic::Control.instance['capture_memcache_keys']
  "NewRelic::Agent.instance.transaction_sampler.notice_nosql(args.first.inspect, (Time.now - t0).to_f) rescue nil"
end