Module: Instana::Instrumentation::Dalli

Defined in:
lib/instana/instrumentation/dalli.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



4
5
6
7
# File 'lib/instana/instrumentation/dalli.rb', line 4

def self.included(klass)
  ::Instana::Util.method_alias(klass, :perform)
  ::Instana::Util.method_alias(klass, :get_multi)
end

Instance Method Details

#get_multi_with_instana(*keys) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/instana/instrumentation/dalli.rb', line 37

def get_multi_with_instana(*keys)
  entry_payload = { :memcache => {} }
  entry_payload[:memcache][:namespace] = @options[:namespace] if @options.key?(:namespace)
  entry_payload[:memcache][:command] = :get_multi
  entry_payload[:memcache][:keys] = keys.flatten.join(", ")

  ::Instana.tracer.log_entry(:memcache, entry_payload)
  result = get_multi_without_instana(*keys)

  exit_payload = { :memcache => {} }
  exit_payload[:memcache][:hits] = result.length
  result
rescue => e
  ::Instana.tracer.log_error(e)
  raise
ensure
  ::Instana.tracer.log_exit(:memcache, exit_payload)
end

#perform_with_instana(*args, &blk) ⇒ 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
# File 'lib/instana/instrumentation/dalli.rb', line 9

def perform_with_instana(*args, &blk)
  if !::Instana.tracer.tracing? || ::Instana.tracer.tracing_span?(:memcache)
    do_skip = true
    return perform_without_instana(*args, &blk)
  end

  op, key, *_opts = args

  entry_payload = { :memcache => {} }
  entry_payload[:memcache][:namespace] = @options[:namespace] if @options.key?(:namespace)
  entry_payload[:memcache][:command] = op
  entry_payload[:memcache][:key] = key

  ::Instana.tracer.log_entry(:memcache, entry_payload)
  result = perform_without_instana(*args, &blk)

  kv_payload = { :memcache => {}}
  if op == :get
    kv_payload[:memcache][:hit] = result ? 1 : 0
  end
  result
rescue => e
  ::Instana.tracer.log_error(e)
  raise
ensure
  ::Instana.tracer.log_exit(:memcache, kv_payload) unless do_skip
end