lib/mongo/monitoring/publishable.rb in mongo-2.5.3 vs lib/mongo/monitoring/publishable.rb in mongo-2.6.0

- old
+ new

@@ -1,6 +1,6 @@ -# Copyright (C) 2015 MongoDB, Inc. +# Copyright (C) 2015-2018 MongoDB, Inc. # # Licensed under the Apache License, Version 2.0 (the 'License'); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # @@ -17,10 +17,11 @@ # Defines behaviour for an object that can publish monitoring events. # # @since 2.1.0 module Publishable + include Loggable # @return [ Monitoring ] monitoring The monitoring. attr_reader :monitoring # Publish a command event to the global monitoring. @@ -48,21 +49,24 @@ total_duration = duration(receive_start) + send_duration command_completed(result, address, operation_id, payload, total_duration) result rescue Exception => e total_duration = duration(receive_start) + send_duration - command_failed(address, operation_id, payload, e.message, total_duration) + command_failed(nil, address, operation_id, payload, e.message, total_duration) raise e end end def publish_event(topic, event) monitoring.succeeded(topic, event) end def publish_sdam_event(topic, event) - monitoring.succeeded(topic, event) if monitoring? + return unless monitoring? + + log_debug("EVENT: #{event.inspect}") + monitoring.succeeded(topic, event) end private def command_started(address, operation_id, payload) @@ -74,11 +78,11 @@ def command_completed(result, address, operation_id, payload, duration) document = result ? (result.documents || []).first : nil if error?(document) parser = Error::Parser.new(document) - command_failed(address, operation_id, payload, parser.message, duration) + command_failed(document, address, operation_id, payload, parser.message, duration) else command_succeeded(result, address, operation_id, payload, duration) end end @@ -93,13 +97,13 @@ duration ) ) end - def command_failed(address, operation_id, payload, message, duration) + def command_failed(failure, address, operation_id, payload, message, duration) monitoring.failed( Monitoring::COMMAND, - Event::CommandFailed.generate(address, operation_id, payload, message, duration) + Event::CommandFailed.generate(address, operation_id, payload, message, failure, duration) ) end def duration(start) Time.now - start