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

Extended by:
Helper
Defined in:
lib/new_relic/agent/instrumentation/memcache/prepend.rb

Constant Summary

Constants included from Helper

Helper::BINARY_PROTOCOL_SUPPORTED_VERSION, Helper::DATASTORE_INSTANCES_SUPPORTED_VERSION

Class Method Summary collapse

Methods included from Helper

client_methods, dalli_cas_methods, dalli_methods, instrument_methods, supported_methods_for, supports_binary_protocol?, supports_datastore_instances?

Class Method Details

.client_prepender(client_class) ⇒ Object



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

def client_prepender(client_class)
  Module.new do
    extend Helper
    include NewRelic::Agent::Instrumentation::Memcache::Tracer

    supported_methods_for(client_class, client_methods).each do |method_name|
      define_method method_name do |*args, &block|
        with_newrelic_tracing(method_name, *args) { super(*args, &block) }
      end
    end
  end
end

.dalli_cas_prependers {|::Dalli::Client, dalli_client_prepender(dalli_cas_methods)| ... } ⇒ Object

Yields:



25
26
27
28
# File 'lib/new_relic/agent/instrumentation/memcache/prepend.rb', line 25

def dalli_cas_prependers
  yield(::Dalli::Client, dalli_client_prepender(dalli_cas_methods))
  yield(::Dalli::Client, dalli_get_multi_prepender(:get_multi_cas))
end

.dalli_client_prepender(supported_methods) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/new_relic/agent/instrumentation/memcache/prepend.rb', line 47

def dalli_client_prepender(supported_methods)
  Module.new do
    extend Helper
    include NewRelic::Agent::Instrumentation::Memcache::Tracer

    supported_methods.each do |method_name|
      define_method method_name do |*args, &block|
        with_newrelic_tracing(method_name, *args) { super(*args, &block) }
      end
    end
  end
end

.dalli_get_multi_prepender(method_name) ⇒ Object



60
61
62
63
64
65
66
67
68
69
# File 'lib/new_relic/agent/instrumentation/memcache/prepend.rb', line 60

def dalli_get_multi_prepender(method_name)
  Module.new do
    extend Helper
    include NewRelic::Agent::Instrumentation::Memcache::Tracer

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

.dalli_prependersObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/new_relic/agent/instrumentation/memcache/prepend.rb', line 30

def dalli_prependers
  if supports_datastore_instances?
    yield(::Dalli::Client, dalli_client_prepender(dalli_methods))
    yield(::Dalli::Client, dalli_get_multi_prepender(:get_multi))

    if supports_binary_protocol?
      yield(::Dalli::Protocol::Binary, dalli_server_prepender)
    else
      yield(::Dalli::Server, dalli_server_prepender)
    end

    yield(::Dalli::Ring, dalli_ring_prepender)
  else
    yield(::Dalli::Client, dalli_client_prepender(client_methods))
  end
end

.dalli_ring_prependerObject



71
72
73
74
75
76
77
78
79
80
# File 'lib/new_relic/agent/instrumentation/memcache/prepend.rb', line 71

def dalli_ring_prepender
  Module.new do
    extend Helper
    include NewRelic::Agent::Instrumentation::Memcache::Tracer

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

.dalli_server_prependerObject



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/new_relic/agent/instrumentation/memcache/prepend.rb', line 82

def dalli_server_prepender
  Module.new do
    extend Helper
    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')
      def pipelined_get(keys)
        send_multiget_with_newrelic_tracing(keys) { super }
      end
    else
      def send_multiget(keys)
        send_multiget_with_newrelic_tracing(keys) { super }
      end
    end
  end
end