123456789_123456789_123456789_123456789_123456789_

Class: Mongo::Monitoring::Event::CommandFailed

Relationships & Source Files
Super Chains via Extension / Inclusion / Inheritance
Class Chain:
Instance Chain:
Inherits: Mongo::Event::Base
Defined in: lib/mongo/monitoring/event/command_failed.rb

Overview

::Mongo::Monitoring::Event that is fired when a command operation fails.

Since:

  • 2.1.0

Constant Summary

Secure - Included

REDACTED_COMMANDS

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Secure - Included

#compression_allowed?

Is compression allowed for a given command message.

#redacted

Redact secure information from the document if:

#sensitive?

Check whether the command is sensitive in terms of command monitoring spec.

::Mongo::Event::Base - Inherited

#summary

Returns a concise yet useful summary of the event.

#short_class_name

Constructor Details

.new(command_name, database_name, address, request_id, operation_id, message, failure, duration, started_event:, server_connection_id: nil, service_id: nil) ⇒ CommandFailed

Create the new event.

Examples:

Create the event.

Parameters:

  • command_name (String) —

    The name of the command.

  • database_name (String) —

    The database_name name.

  • address (Server::Address) —

    The server address.

  • request_id (Integer) —

    The request id.

  • operation_id (Integer) —

    The operation id.

  • message (String) —

    The error message.

  • failure (BSON::Document) —

    The error document, if any.

  • duration (Float) —

    The duration the command took in seconds.

  • started_event (Monitoring::Event::CommandStarted) —

    The corresponding started event.

  • service_id (Object) —

    The service id, if any.

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/monitoring/event/command_failed.rb', line 83

def initialize(command_name, database_name, address,
               request_id, operation_id, message, failure, duration,
               started_event:, server_connection_id: nil, service_id: nil)
  super()
  @command_name = command_name.to_s
  @database_name = database_name
  @address = address
  @request_id = request_id
  @operation_id = operation_id
  @service_id = service_id
  @message = message
  @started_event = started_event
  @failure = redacted(command_name, failure)
  @duration = duration
  @server_connection_id = server_connection_id
end

Class Method Details

.generate(address, operation_id, payload, message, failure, duration, started_event:, server_connection_id: nil, service_id: nil) ⇒ CommandFailed

Create the event from a wire protocol message payload.

Examples:

Create the event.

CommandFailed.generate(address, 1, payload, duration)

Parameters:

  • address (Server::Address) —

    The server address.

  • operation_id (Integer) —

    The operation id.

  • payload (Hash) —

    The message payload.

  • message (String) —

    The error message.

  • failure (BSON::Document) —

    The error document, if any.

  • duration (Float) —

    The duration of the command in seconds.

  • started_event (Monitoring::Event::CommandStarted) —

    The corresponding started event.

  • service_id (Object) —

    The service id, if any.

Returns:

  • (CommandFailed) —

    The event.

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/monitoring/event/command_failed.rb', line 130

def self.generate(address, operation_id, payload, message,
                  failure, duration, started_event:, server_connection_id: nil,
                  service_id: nil)
  new(
    payload[:command_name],
    payload[:database_name],
    address,
    payload[:request_id],
    operation_id,
    message,
    failure,
    duration,
    started_event: started_event,
    server_connection_id: server_connection_id,
    service_id: service_id
  )
end

Instance Attribute Details

#address ⇒ Server::Address (readonly)

Returns:

  • (Server::Address) —

    address The server address.

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/monitoring/event/command_failed.rb', line 27

attr_reader :address

#command_name ⇒ String (readonly)

Returns:

  • (String) —

    command_name The name of the command.

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/monitoring/event/command_failed.rb', line 30

attr_reader :command_name

#database_name ⇒ String (readonly)

Returns:

  • (String) —

    database_name The name of the database_name.

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/monitoring/event/command_failed.rb', line 33

attr_reader :database_name

#duration ⇒ Float (readonly)

Returns:

  • (Float) —

    duration The duration of the command in seconds.

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/monitoring/event/command_failed.rb', line 36

attr_reader :duration

#failure ⇒ BSON::Document (readonly)

Returns:

  • (BSON::Document) —

    failure The error document, if present. This will only be filled out for errors communicated by a MongoDB server. In other situations, for example in case of a network error, this attribute may be nil.

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/monitoring/event/command_failed.rb', line 42

attr_reader :failure

#message ⇒ String (readonly)

Returns:

  • (String) —

    message The error message. Unlike the error document, the error message should always be present.

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/monitoring/event/command_failed.rb', line 46

attr_reader :message

#operation_id ⇒ Integer (readonly)

Returns:

  • (Integer) —

    operation_id The operation id.

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/monitoring/event/command_failed.rb', line 49

attr_reader :operation_id

#request_id ⇒ Integer (readonly)

Returns:

  • (Integer) —

    request_id The request id.

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/monitoring/event/command_failed.rb', line 52

attr_reader :request_id

#server_connection_id ⇒ Integer (readonly)

Returns:

  • (Integer) —

    server_connection_id The server connection id.

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/monitoring/event/command_failed.rb', line 55

attr_reader :server_connection_id

#service_id ⇒ nil | Object (readonly)

Returns:

  • (nil | Object) —

    The service id, if any.

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/monitoring/event/command_failed.rb', line 58

attr_reader :service_id

#started_event ⇒ Monitoring::Event::CommandStarted (readonly)

Returns:

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/monitoring/event/command_failed.rb', line 64

attr_reader :started_event

Instance Method Details

#summary ⇒ String

Note:

This method is experimental and subject to change.

Returns a concise yet useful summary of the event.

Returns:

  • (String) —

    String summary of the event.

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/monitoring/event/command_failed.rb', line 107

def summary
  "#<#{short_class_name} address=#{address} #{database_name}.#{command_name}>"
end