Module: Instana::Instrumentation::ResqueClient

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.prepended(klass) ⇒ Object



9
10
11
# File 'lib/instana/instrumentation/resque.rb', line 9

def self.prepended(klass)
  klass.send :extend, ::Resque
end

Instance Method Details

#collect_kvs(op, klass, args) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/instana/instrumentation/resque.rb', line 13

def collect_kvs(op, klass, args)
  kvs = {}

  begin
    kvs[:job] = klass.to_s
    kvs[:queue] = klass.instance_variable_get(:@queue)
  rescue => e
    Instana.logger.debug { "#{__method__}:#{File.basename(__FILE__)}:#{__LINE__}: #{e.message}" }
  end

  { :'resque-client' => kvs }
end

#dequeue(klass, *args) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/instana/instrumentation/resque.rb', line 53

def dequeue(klass, *args)
  if Instana.tracer.tracing?
    kvs = collect_kvs(:dequeue, klass, args)

    Instana.tracer.in_span(:'resque-client', attributes: kvs) do
      super(klass, *args)
    end
  else
    super(klass, *args)
  end
end

#enqueue(klass, *args) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/instana/instrumentation/resque.rb', line 26

def enqueue(klass, *args)
  if Instana.tracer.tracing?
    kvs = collect_kvs(:enqueue, klass, args)

    Instana.tracer.in_span(:'resque-client', attributes: kvs) do
      args.push(::Instana.tracer.context.to_hash) if ::Instana.config[:'resque-client'][:propagate]
      super(klass, *args)
    end
  else
    super(klass, *args)
  end
end

#enqueue_to(queue, klass, *args) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/instana/instrumentation/resque.rb', line 39

def enqueue_to(queue, klass, *args)
  if Instana.tracer.tracing? && !Instana.tracer.tracing_span?(:'resque-client')
    kvs = collect_kvs(:enqueue_to, klass, args)
    kvs[:Queue] = queue.to_s if queue

    Instana.tracer.in_span(:'resque-client', attributes: kvs) do
      args.push(::Instana.tracer.context.to_hash) if ::Instana.config[:'resque-client'][:propagate]
      super(queue, klass, *args)
    end
  else
    super(queue, klass, *args)
  end
end