class Object

Public Instance Methods

logging_with_newrelic_trace(operations, &blk) click to toggle source
# File lib/newrelic-moped/instrument.rb, line 17
def logging_with_newrelic_trace(operations, &blk)
  log_statement = operations.first.log_inspect
  collection = "Unknown"
  if operations.first.respond_to?(:collection)
    collection = operations.first.collection
  end
  operation_name = log_statement.split[0]
  if operation_name == 'COMMAND' && log_statement.include?(":mapreduce")
    operation_name = 'MAPREDUCE'
    collection = log_statement[/:mapreduce=>"([^"]+)/,1]
  elsif operation_name == 'COMMAND' && log_statement.include?(":count")
    operation_name = 'COUNT'
    collection = log_statement[/:count=>:([^,]+)/,1]
  end

  self.class.trace_execution_scoped("Database/#{collection}/#{operation_name}") do
    t0 = Time.now
    res = logging_without_newrelic_trace(operations, &blk)
    elapsed_time = (Time.now - t0).to_f
    NewRelic::Agent.instance.transaction_sampler.notice_sql(log_statement, nil, elapsed_time)
    NewRelic::Agent.instance.sql_sampler.notice_sql(log_statement, nil, nil, elapsed_time)
    res
  end
end