Method: Hallmonitor::Monitored::ClassMethods#timer_for
- Defined in:
- lib/hallmonitor/monitored.rb
#timer_for(method_sym, metric_name: nil, tags: {}) ⇒ Object
Sets up a timer for a method by symbol. Method must have already been defined (ie. put this after the method definition)
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/hallmonitor/monitored.rb', line 12 def timer_for(method_sym, metric_name: nil, tags: {}) metric_name ||= "#{underscore(name)}.#{method_sym}" undecorated_method_sym = "#{method_sym}_without_hallmonitor_timer".to_sym decorated_method_sym = "#{method_sym}_with_hallmonitor_timer".to_sym send(:define_method, decorated_method_sym) do |*args| watch(metric_name, tags: ) do send(undecorated_method_sym, *args) end end alias_method undecorated_method_sym, method_sym alias_method method_sym, decorated_method_sym end |