Module: NewRelic::Agent::Instrumentation::Memcache

Defined in:
lib/new_relic/agent/instrumentation/memcache.rb

Class Method Summary collapse

Class Method Details

.instrument_methods(the_class, method_names) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/new_relic/agent/instrumentation/memcache.rb', line 17

def instrument_methods(the_class, method_names)
  method_names.each do |method_name|
    next unless the_class.method_defined? method_name.to_sym
    the_class.class_eval <<-EOD
      def #{method_name}_with_newrelic_trace(*args, &block)
        metrics = ["Memcache/#{method_name}",
                   (NewRelic::Agent::Transaction.recording_web_transaction? ? 'Memcache/allWeb' : 'Memcache/allOther')]
        self.class.trace_execution_scoped(metrics) do
          t0 = Time.now
          begin
            #{method_name}_without_newrelic_trace(*args, &block)
          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
end

.memcache_key_snippet(method_name) ⇒ Object



38
39
40
41
# File 'lib/new_relic/agent/instrumentation/memcache.rb', line 38

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