module Mongo::Monitoring
Overview
Provides runtime information about commands to any 3rd party APM library as well internal driver use, such as logging.
client = Mongo::Client.new
subscription = client.subscribe_commands { |event|
case event
when Mongo::Monitoring::Commands::CommandStartedEvent
Log.info { "COMMAND.#{event.command_name} #{event.address} STARTED: #{event.command.to_json}" }
when Mongo::Monitoring::Commands::CommandSucceededEvent
Log.info { "COMMAND.#{event.command_name} #{event.address} COMPLETED: #{event.reply.to_json} (#{event.duration}s)" }
when Mongo::Monitoring::Commands::CommandFailedEvent
Log.info { "COMMAND.#{event.command_name} #{event.address} FAILED: #{event.failure.inspect} (#{event.duration}s)" }
end
}
client.unsubscribe_commands(subscription)