Module: Metrics::Instrumentable::ClassMethods
- Defined in:
- lib/metrics/instrumentable.rb
Instance Method Summary collapse
-
#instrument(*methods) ⇒ Object
Public: Wraps the method with a call to instrument the duration of the method.
-
#metric_namespace ⇒ Object
Internal: Used internally to specify the namespace for method instrumentation.
Instance Method Details
#instrument(*methods) ⇒ Object
Public: Wraps the method with a call to instrument the duration of the method. Fancy!
Example
def some_method
do_something_taxing
end
instrument :some_method
# => 'source=app measure.some_method=10s'
Returns nothing.
57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/metrics/instrumentable.rb', line 57 def instrument(*methods) methods.each do |name| visibility = %w[public private protected].find { |visibility| send :"#{visibility}_method_defined?", name } method = instance_method(name) define_method name do |*args, &block| bound_method = method.bind(self) instrument [self.class.metric_namespace, name].join('.') do bound_method.call(*args, &block) end end send visibility, name end end |
#metric_namespace ⇒ Object
Internal: Used internally to specify the namespace for method instrumentation.
Override this in your class if you need it to be something different.
Example
module Some
class Namespace
include Metrics::Instrumentable
def long_method; end
instrument :long_method
end
end
Some::Namespace.metric_namespace # => ‘some.namespace’
Some::Namespace.new.long_method # => ‘source=app measure.some.namespace.long_method=10s’
Returns a String namespace for the metric.
40 41 42 |
# File 'lib/metrics/instrumentable.rb', line 40 def metric_namespace to_s.gsub(/::/, '.').underscore end |