class AlacrityRails::Probe::MongoDriver

Public Class Methods

activate() click to toggle source
# File lib/alacrity-rails/probe/mongo_driver.rb, line 4
def self.activate
  if defined?(Mongo)
    Mongo::Monitoring::Global.subscribe(Mongo::Monitoring::COMMAND, new)
  end
end

Public Instance Methods

failed(event)
Alias for: succeeded
start_events() click to toggle source
# File lib/alacrity-rails/probe/mongo_driver.rb, line 10
def start_events
  @start_events ||= {}
end
started(event) click to toggle source
# File lib/alacrity-rails/probe/mongo_driver.rb, line 14
def started(event)
  start_events[event.operation_id] = { started_at: DateTime.now, command: event.command }
end
succeeded(event) click to toggle source
# File lib/alacrity-rails/probe/mongo_driver.rb, line 18
def succeeded(event)
  finished = DateTime.now
  start_event = start_events.delete(event.operation_id)

  command = {}
  start_event[:command].each do |key, value|
    command[key] = value.respond_to?(:keys) ? value.keys : value
  end

  store(event.command_name, start_event[:started_at], finished, command)
rescue => error
  Logger.error("Alacrity mongo driver tracking failed: #{error.inspect}")
end
Also aliased as: failed

Protected Instance Methods

store(command_name, started_at, finished_at, command) click to toggle source
# File lib/alacrity-rails/probe/mongo_driver.rb, line 35
def store(command_name, started_at, finished_at, command)
  AlacrityRails::Client.store_timeline_event(
    name: command_name,
    event_type: 'database',
    engine: 'Mongo',
    started_at: started_at,
    finished_at: finished_at,
    detail: command.to_s
  )
end