Module: Cequel::Instrumentation::ModuleMethods
- Defined in:
- lib/cequel/instrumentation.rb
Overview
Metaprogramming method to wrap an existing method with instrumentation
Instance Method Summary collapse
-
#instrument(method_name, opts) ⇒ Object
Instruments ‘method_name` to publish the value returned by the `data_builder` proc onto `topic`.
Instance Method Details
#instrument(method_name, opts) ⇒ Object
Instruments ‘method_name` to publish the value returned by the `data_builder` proc onto `topic`
Example:
extend Instrumentation
instrument :create, "create.cequel", data: {table_name: table_name}
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/cequel/instrumentation.rb', line 28 def instrument(method_name, opts) data = opts[:data] topic = opts.fetch(:topic, "#{method_name}.cequel") data_proc = if data.respond_to? :call data else ->(_) { data } end define_method(:"__data_for_#{method_name}_instrumentation", &data_proc) module_eval <<-METH def #{method_name}_with_instrumentation(*args) instrument("#{topic}", __data_for_#{method_name}_instrumentation(self)) do #{method_name}_without_instrumentation(*args) end end METH alias_method_chain method_name, "instrumentation" end |