Module: Etna::Instrumentation
- Included in:
- Route
- Defined in:
- lib/etna/instrumentation.rb
Class Method Summary collapse
Instance Method Summary collapse
- #has_yabeda? ⇒ Boolean
- #increment_it(&block) ⇒ Object
- #time_it(method_name, args, &metric_block) ⇒ Object
- #with_yabeda_tags(tags, &block) ⇒ Object
Class Method Details
.included(cls) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 |
# File 'lib/etna/instrumentation.rb', line 3 def self.included(cls) cls.instance_eval do def self.time_it(method_name, &metric_block) orig_method_name = :"#{method_name}_without_time_it" self.alias_method orig_method_name, method_name self.define_method method_name do |*args| time_it(orig_method_name, args, &metric_block) end end end end |
Instance Method Details
#has_yabeda? ⇒ Boolean
52 53 54 |
# File 'lib/etna/instrumentation.rb', line 52 def has_yabeda? defined?(Yabeda) && Yabeda.configured? end |
#increment_it(&block) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/etna/instrumentation.rb', line 16 def increment_it(&block) if has_yabeda? metric = yield metric.increment({}) end end |
#time_it(method_name, args, &metric_block) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/etna/instrumentation.rb', line 23 def time_it(method_name, args, &metric_block) if has_yabeda? start = Process.clock_gettime(Process::CLOCK_MONOTONIC) begin return send(method_name, *args) ensure dur = Process.clock_gettime(Process::CLOCK_MONOTONIC) - start if block_given? metric = yield = {} else = {class_name: self.class.name, method_name: method_name.to_s} metric = Yabeda.etna.perf end metric.measure(, dur) end else return send(method_name, *args, **kwds) end end |
#with_yabeda_tags(tags, &block) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/etna/instrumentation.rb', line 44 def (, &block) if has_yabeda? Yabeda.(, &block) else yield end end |