Sha256: 5068668e86b6be236a161451e2ce77dd43538329dcd0a59f09ec9c7a41e84a25

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

Mongo::Cursor.class_eval do
  alias_method :original_send_initial_query, :send_initial_query

  def send_initial_query
    beginning_time = Time.now
    original_send_initial_query
    total_time = Time.now - beginning_time
    begin
      _caller = MongoProfiler::Caller.new(caller)

      return if MongoProfiler.should_skip?(instrument_payload, _caller) || MongoProfiler.disabled?

      result = {}

      result[:total_time] = total_time

      # the payload sent to mongo
      result[:instrument_payload] = JSON.dump(instrument_payload)

      result[:file]   = _caller.file
      result[:line]   = _caller.line
      result[:method] = _caller.method

      result[:extra_attrs] = MongoProfiler.extra_attrs

      # TODO rename `_caller` object instance to something more meaningful in this context
      result[:backtrace]  = _caller._caller

      MongoProfiler.log(result)

      if stats_client = MongoProfiler.stats_client
        stats_client.populate(_caller, total_time)
      end
    rescue => e
      p "MongoProfiler: #{e.message}"
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mongo_profiler-0.0.1 lib/mongo_profiler/extensions/mongo/cursor.rb