24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/one_apm/inst/nosql/memcache.rb', line 24
def instrument_methods(client_class, requested_methods = OA_METHODS)
supported_methods_for(client_class, requested_methods).each do |method_name|
visibility = OneApm::Helper.instance_method_visibility client_class, method_name
method_name_without = :"#{method_name}_without_oneapm_trace"
client_class.class_eval do
alias_method method_name_without, method_name
if defined?(::MemCache)
def oneapm_product
@product ||= begin
s = Array(servers)
host, port = s.first.host, s.first.port if s.first rescue nil
OneApm::Agent::Datastore.oneapm_product("Memcached", host, port)
end
end
private :oneapm_product
else
def oneapm_product
@product ||= begin
s = Array(@servers || servers)
host, port, weight = s.first.split(":") if s.first && s.first.to_s.include?(':') rescue nil
OneApm::Agent::Datastore.oneapm_product("Memcached", host, port)
end
end
private :oneapm_product
end
define_method method_name do |*args, &block|
metrics = Datastore::MetricHelper.metrics_for(oneapm_product, method_name)
OneApm::Support::MethodTracer.trace_execution_scoped(metrics) do
t0 = Time.now
begin
send method_name_without, *args, &block
ensure
if OneApm::Manager.config[:capture_memcache_keys]
OneApm::Manager.agent.transaction_sampler.notice_nosql(args.first.inspect, (Time.now - t0).to_f) rescue nil
end
end
end
end
send visibility, method_name
send visibility, method_name_without
end
end
end
|