Module: TraceView::Inst::Memcached

Includes:
API::Memcache
Defined in:
lib/traceview/inst/memcached.rb

Constant Summary

Constants included from API::Memcache

API::Memcache::MEMCACHE_OPS

Class Method Summary collapse

Methods included from API::Memcache

#memcache_hit?, #remote_host

Class Method Details

.included(cls) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/traceview/inst/memcached.rb', line 9

def self.included(cls)
  TraceView.logger.info '[traceview/loading] Instrumenting memcached' if TraceView::Config[:verbose]

  cls.class_eval do
    MEMCACHE_OPS.reject { |m| !method_defined?(m) }.each do |m|
      define_method("#{m}_with_traceview") do |*args|
        opts = { :KVOp => m }

        if args.length && !args[0].is_a?(Array)
          opts[:KVKey] = args[0].to_s
          rhost = remote_host(args[0].to_s)
          opts[:RemoteHost] = rhost if rhost
        end

        TraceView::API.trace('memcache', opts) do
          result = send("#{m}_without_traceview", *args)

          info_kvs = {}
          info_kvs[:KVHit] = memcache_hit?(result) if m == :get && args.length && args[0].class == String
          info_kvs[:Backtrace] = TraceView::API.backtrace if TraceView::Config[:memcached][:collect_backtraces]

          TraceView::API.log('memcache', 'info', info_kvs) unless info_kvs.empty?
          result
        end
      end

      class_eval "alias #{m}_without_traceview #{m}"
      class_eval "alias #{m} #{m}_with_traceview"
    end
  end
end