Method: Hallmonitor::Monitored::ClassMethods#count_for

Defined in:
lib/hallmonitor/monitored.rb

#count_for(method_sym, metric_name: nil, tags: {}) ⇒ Object

Sets up a counter for a method by symbol. Method must have already been defined (ie. put this after the method definition)

Parameters:

  • method_sym (Symbol)

    method name as a symbol



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/hallmonitor/monitored.rb', line 32

def count_for(method_sym, metric_name: nil, tags: {})
  metric_name ||= "#{underscore(name)}.#{method_sym}"
  undecorated_method_sym = "#{method_sym}_without_hallmonitor_counter".to_sym
  decorated_method_sym = "#{method_sym}_with_hallmonitor_counter".to_sym
  send(:define_method, decorated_method_sym) do |*args|
    emit(metric_name, tags: tags)
    send(undecorated_method_sym, *args)
  end

  alias_method undecorated_method_sym, method_sym
  alias_method method_sym, decorated_method_sym
end