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, callback = nil) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/ting_yun/agent/datastore.rb', line 12

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

  metrics = TingYun::Agent::Datastore::MetricHelper.metrics_for(product, operation, collection)

  scoped_metric = metrics.last

  TingYun::Agent::MethodTracer.trace_execution_scoped(metrics) do
    t0 = Time.now
    begin
      result = yield
    ensure
      elapsed_time = (Time.now - t0).to_f
      if callback
        callback.call(result, scoped_metric, elapsed_time)
      end
    end
  end
end