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

Extended by:
Helper
Included in:
DalliCAS
Defined in:
lib/new_relic/agent/instrumentation/memcache/dalli.rb

Class Method Summary collapse

Methods included from Helper

correctly_encoded, executable_in_path?, instance_method_visibility, instance_methods_include?, run_command, time_to_millis

Class Method Details

.instrument!Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/new_relic/agent/instrumentation/memcache/dalli.rb', line 14

def instrument!
  if supports_datastore_instances?
    instrument_methods(::Dalli::Client, dalli_methods)
    instrument_multi_method(:get_multi)
    instrument_send_multiget
    instrument_server_for_key
  else
    instrument_methods(::Dalli::Client, client_methods)
  end
end

.instrument_multi_method(method_name) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/new_relic/agent/instrumentation/memcache/dalli.rb', line 25

def instrument_multi_method(method_name)
  visibility = NewRelic::Helper.instance_method_visibility(::Dalli::Client, method_name)
  method_name_without = :"#{method_name}_without_newrelic_trace"

  ::Dalli::Client.class_eval do
    alias_method(method_name_without, method_name)

    define_method(method_name) do |*args, &block|
      get_multi_with_newrelic_tracing(method_name) { __send__(method_name_without, *args, &block) }
    end

    __send__(visibility, method_name)
    __send__(visibility, method_name_without)
  end
end

.instrument_send_multigetObject



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/new_relic/agent/instrumentation/memcache/dalli.rb', line 53

def instrument_send_multiget
  if supports_binary_protocol?
    ::Dalli::Protocol::Binary
  else
    ::Dalli::Server
  end.class_eval do
    include NewRelic::Agent::Instrumentation::Memcache::Tracer

    # TODO: MAJOR VERSION
    # Dalli - 3.1.0 renamed send_multiget to pipelined_get, but the method is otherwise the same
    # Once we no longer support Dalli < 3.1.0, remove this conditional logic
    if Gem::Version.new(::Dalli::VERSION) >= Gem::Version.new('3.1.0')
      alias_method(:pipelined_get_without_newrelic_trace, :pipelined_get)
      def pipelined_get(keys)
        send_multiget_with_newrelic_tracing(keys) { pipelined_get_without_newrelic_trace(keys) }
      end
    else
      alias_method(:send_multiget_without_newrelic_trace, :send_multiget)
      def send_multiget(keys)
        send_multiget_with_newrelic_tracing(keys) { send_multiget_without_newrelic_trace(keys) }
      end
    end
  end
end

.instrument_server_for_keyObject



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/new_relic/agent/instrumentation/memcache/dalli.rb', line 41

def instrument_server_for_key
  ::Dalli::Ring.class_eval do
    include NewRelic::Agent::Instrumentation::Memcache::Tracer

    alias_method(:server_for_key_without_newrelic_trace, :server_for_key)

    def server_for_key(key)
      server_for_key_with_newrelic_tracing { server_for_key_without_newrelic_trace(key) }
    end
  end
end