Module: TingYun::Agent::Datastore

Defined in:
lib/ting_yun/agent/datastore.rb,
lib/ting_yun/agent/datastore/mongo.rb,
lib/ting_yun/agent/datastore/metric_helper.rb

Defined Under Namespace

Modules: MetricHelper, Mongo

Class Method Summary collapse

Class Method Details

.wrap(product, operation, collection = nil, ip_address = nil, port = nil, dbname = nil, callback = nil) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/ting_yun/agent/datastore.rb', line 10

def self.wrap(product, operation, collection = nil, ip_address = nil, port = nil, dbname=nil,  callback = nil )
  return yield unless operation

  klass_name, *metrics = TingYun::Agent::Datastore::MetricHelper.metrics_for(product, operation, ip_address , port, dbname,collection )
  TingYun::Agent::MethodTracerHelpers.trace_execution_scoped(metrics, {}, nil, klass_name) do
    t0 = Time.now
    begin
      yield
    ensure
      elapsed_time = (Time.now - t0).to_f
      if callback
        callback.call(elapsed_time)
      end
    end
  end
end