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

- old
+ new

@@ -21,28 +21,34 @@ end def hook_instrument_method(target_class) target_class.class_eval do - require 'ting_yun/agent/method_tracer' + require 'ting_yun/agent/method_tracer_helpers' def record_mongo_duration(duration) state = TingYun::Agent::TransactionState.tl_get if state state.timings.mon_duration = state.timings.mon_duration + duration * 1000 end end + def tingyun_host_port + return @db.connection.host_port if self.instance_variable_defined? :@db + return @host_to_try if self.instance_variable_defined? :@host_to_try + return ['Unknown', 'Unknown'] + end + def tingyun_generate_metrics(operation, payload = nil) payload ||= { :collection => self.name, :database => self.db.name } - TingYun::Instrumentation::Support::MetricTranslator.metrics_for(operation, payload) + TingYun::Instrumentation::Support::MetricTranslator.metrics_for(operation, payload, tingyun_host_port) end def instrument_with_tingyun(name, payload = {}, &block) - metrics = tingyun_generate_metrics(name, payload) + klass_name, *metrics = tingyun_generate_metrics(name, payload) - TingYun::Agent::MethodTracer.trace_execution_scoped(metrics, payload, method(:record_mongo_duration)) do + TingYun::Agent::MethodTracerHelpers.trace_execution_scoped(metrics, payload, method(:record_mongo_duration), klass_name) do instrument_without_tingyun(name, payload, &block) end end alias_method :instrument_without_tingyun, :instrument @@ -51,20 +57,22 @@ end def instrument ::Mongo::Collection.class_eval do def save_with_tingyun(doc, opts = {}, &block) - TingYun::Agent::MethodTracer.trace_execution_scoped(tingyun_generate_metrics(:save), opts, method(:record_mongo_duration)) do + klass_name, *metrics = tingyun_generate_metrics(:save) + TingYun::Agent::MethodTracerHelpers.trace_execution_scoped(metrics, opts, method(:record_mongo_duration), klass_name) do save_without_tingyun(doc, opts, &block) end end alias_method :save_without_tingyun, :save alias_method :save, :save_with_tingyun def ensure_index_with_tingyun(spec, opts = {}, &block) - TingYun::Agent::MethodTracer.trace_execution_scoped(tingyun_generate_metrics(:ensureIndex), opts, method(:record_mongo_duration)) do + klass_name, *metrics = tingyun_generate_metrics(:ensureIndex) + TingYun::Agent::MethodTracerHelpers.trace_execution_scoped(metrics, opts, method(:record_mongo_duration), klass_name) do ensure_index_without_tingyun(spec, opts, &block) end end alias_method :ensure_index_without_tingyun, :ensure_index @@ -76,9 +84,13 @@ end end TingYun::Support::LibraryDetection.defer do named :mongo + + depends_on do + !::TingYun::Agent.config[:disable_mongo] + end depends_on do defined?(::Mongo) end