Class: Twirl::Instrumentation::Subscriber

Inherits:
Object
  • Object
show all
Defined in:
lib/twirl/instrumentation/subscriber.rb

Direct Known Subclasses

StatsdSubscriber

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, start, ending, transaction_id, payload) ⇒ Subscriber

Private: Initializes a new event processing instance.



10
11
12
13
14
15
16
17
# File 'lib/twirl/instrumentation/subscriber.rb', line 10

def initialize(name, start, ending, transaction_id, payload)
  @name = name
  @start = start
  @ending = ending
  @payload = payload
  @duration = ending - start
  @transaction_id = transaction_id
end

Class Method Details

.call(name, start, ending, transaction_id, payload) ⇒ Object

Public: Use this as the subscribed block.



5
6
7
# File 'lib/twirl/instrumentation/subscriber.rb', line 5

def self.call(name, start, ending, transaction_id, payload)
  new(name, start, ending, transaction_id, payload).update
end

Instance Method Details

#updateObject

Public: Actually update all the metriks timers for the event.

Returns nothing.



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/twirl/instrumentation/subscriber.rb', line 22

def update
  op = @payload[:op]
  bytes = @payload[:bytes]
  queue_name = @payload[:queue_name]
  metric_type = @payload[:metric_type] || :timer

  return unless op

  send "update_#{metric_type}", "twirl.op_#{op}"

  if @payload[:retry]
    update_counter "twirl.retries_op_#{op}"
  end

  if bytes
    update_counter "twirl.bytes_op_#{op}"

    if queue_name
      update_counter "twirl.bytes_queue_#{queue_name}_op_#{op}"
    end
  end

  if queue_name
    update_timer "twirl.queue_#{queue_name}_op_#{op}"
  end
end

#update_counter(metric, value = 1) ⇒ Object

Internal: Override in subclass.

Raises:

  • (NotImplementedError)


55
56
57
# File 'lib/twirl/instrumentation/subscriber.rb', line 55

def update_counter(metric, value = 1)
  raise NotImplementedError
end

#update_timer(metric) ⇒ Object

Internal: Override in subclass.

Raises:

  • (NotImplementedError)


50
51
52
# File 'lib/twirl/instrumentation/subscriber.rb', line 50

def update_timer(metric)
  raise NotImplementedError
end