lib/ting_yun/instrumentation/mongo.rb in tingyun_rpm-1.1.4.2 vs lib/ting_yun/instrumentation/mongo.rb in tingyun_rpm-1.2.0

- old
+ new

@@ -8,12 +8,11 @@ module Mongo extend self def install_mongo_instrumentation hook_instrument_methods - instrument_save - instrument_ensure_index + instrument end def hook_instrument_methods hook_instrument_method(::Mongo::Collection) hook_instrument_method(::Mongo::Connection) @@ -26,59 +25,54 @@ target_class.class_eval do require 'ting_yun/agent/method_tracer' def record_mongo_duration(duration) state = TingYun::Agent::TransactionState.tl_get - unless state.nil? - state.mon_duration += duration * 1000 + if state + state.timings.mon_duration = state.timings.mon_duration + duration * 1000 end end - def ting_yun_generate_metrics(operation, payload = nil) + def tingyun_generate_metrics(operation, payload = nil) payload ||= { :collection => self.name, :database => self.db.name } TingYun::Instrumentation::Support::MetricTranslator.metrics_for(operation, payload) end - def instrument_with_ting_yun_trace(name, payload = {}, &block) - metrics = ting_yun_generate_metrics(name, payload) + def instrument_with_tingyun(name, payload = {}, &block) + metrics = tingyun_generate_metrics(name, payload) TingYun::Agent::MethodTracer.trace_execution_scoped(metrics, payload, method(:record_mongo_duration)) do - instrument_without_ting_yun_trace(name, payload, &block) + instrument_without_tingyun(name, payload, &block) end end - alias_method :instrument_without_ting_yun_trace, :instrument - alias_method :instrument, :instrument_with_ting_yun_trace + alias_method :instrument_without_tingyun, :instrument + alias_method :instrument, :instrument_with_tingyun end end - def instrument_save + def instrument ::Mongo::Collection.class_eval do - def save_with_ting_yun_trace(doc, opts = {}, &block) - metrics = ting_yun_generate_metrics(:save) - TingYun::Agent::MethodTracer.trace_execution_scoped(metrics, opts, method(:record_mongo_duration)) do - save_without_ting_yun_trace(doc, opts, &block) + def save_with_tingyun(doc, opts = {}, &block) + TingYun::Agent::MethodTracer.trace_execution_scoped(tingyun_generate_metrics(:save), opts, method(:record_mongo_duration)) do + save_without_tingyun(doc, opts, &block) end end - alias_method :save_without_ting_yun_trace, :save - alias_method :save, :save_with_ting_yun_trace - end - end + alias_method :save_without_tingyun, :save + alias_method :save, :save_with_tingyun - def instrument_ensure_index - ::Mongo::Collection.class_eval do - def ensure_index_with_ting_yun_trace(spec, opts = {}, &block) - metrics = ting_yun_generate_metrics(:ensureIndex) - TingYun::Agent::MethodTracer.trace_execution_scoped(metrics, opts, method(:record_mongo_duration)) do - ensure_index_with_out_ting_yun_trace(spec, opts, &block) + def ensure_index_with_tingyun(spec, opts = {}, &block) + TingYun::Agent::MethodTracer.trace_execution_scoped(tingyun_generate_metrics(:ensureIndex), opts, method(:record_mongo_duration)) do + ensure_index_without_tingyun(spec, opts, &block) end end - alias_method :ensure_index_with_out_ting_yun_trace, :ensure_index - alias_method :ensure_index, :ensure_index_with_ting_yun_trace + alias_method :ensure_index_without_tingyun, :ensure_index + alias_method :ensure_index, :ensure_index_with_tingyun end end + end end end TingYun::Support::LibraryDetection.defer do