123456789_123456789_123456789_123456789_123456789_

Class: Mongo::Monitoring::Event::CommandStarted

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

Overview

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

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

Class Method Details

.generate(address, operation_id, payload, socket_object_id: nil, connection_id: nil, connection_generation: nil, server_connection_id: nil, service_id: nil) ⇒ CommandStarted

This method is for internal use only.

Create the event from a wire protocol message payload.

Examples:

Create the event.

CommandStarted.generate(address, 1, payload)

Parameters:

  • address (Server::Address)

    The server address.

  • operation_id (Integer)

    The operation id.

  • payload (Hash)

    The message payload.

  • service_id (Object)

    The service id, if any.

Returns:

  • (CommandStarted)

    The event.

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/monitoring/event/command_started.rb', line 150

def self.generate(address, operation_id, payload,
  socket_object_id: nil, connection_id: nil, connection_generation: nil,
  server_connection_id: nil, service_id: nil
)
  new(
    payload[:command_name],
    payload[:database_name],
    address,
    payload[:request_id],
    operation_id,
    # All op_msg  payloads have a $db field. Legacy payloads do not
    # have a $db field. To emulate op_msg when publishing command
    # monitoring events for legacy servers, add $db to the payload,
    # copying the database name. Note that the database name is also
    # available as a top-level attribute on the command started event.
    payload[:command].merge('$db' => payload[:database_name]),
    socket_object_id: socket_object_id,
    connection_id: connection_id,
    connection_generation: connection_generation,
    server_connection_id: server_connection_id,
    service_id: service_id,
  )
end

Instance Attribute Details

#addressServer::Address (readonly)

Returns:

  • (Server::Address)

    address The server address.

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/monitoring/event/command_started.rb', line 29

attr_reader :address

#commandBSON::Document (readonly)

Returns:

  • (BSON::Document)

    command The command arguments.

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/monitoring/event/command_started.rb', line 32

attr_reader :command

#command_nameString (readonly)

Returns:

  • (String)

    command_name The name of the command.

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/monitoring/event/command_started.rb', line 35

attr_reader :command_name

#connection_generation (readonly)

This method is for internal use only.

Since:

  • 2.1.0

[ GitHub ]

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

attr_reader :connection_generation

#connection_idInteger (readonly)

This method is for internal use only.

Returns:

  • (Integer)

    The ID for the connection over which the command is sent.

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/monitoring/event/command_started.rb', line 61

attr_reader :connection_id

#database_nameString (readonly)

Returns:

  • (String)

    database_name The name of the database_name.

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/monitoring/event/command_started.rb', line 38

attr_reader :database_name

#operation_idInteger (readonly)

Returns:

  • (Integer)

    operation_id The operation id.

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/monitoring/event/command_started.rb', line 41

attr_reader :operation_id

#request_idInteger (readonly)

Returns:

  • (Integer)

    request_id The request id.

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/monitoring/event/command_started.rb', line 44

attr_reader :request_id

#sensitivetrue | false (readonly)

This method is for internal use only.

Returns:

  • (true | false)

    Whether the event contains sensitive data.

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/monitoring/event/command_started.rb', line 69

attr_reader :sensitive

#server_connection_idInteger (readonly)

Returns:

  • (Integer)

    server_connection_id The server connection id.

Since:

  • 2.1.0

[ GitHub ]

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

attr_reader :server_connection_id

#service_idnil | Object (readonly)

Returns:

  • (nil | Object)

    The service id, if any.

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/monitoring/event/command_started.rb', line 47

attr_reader :service_id

#socket_object_id (readonly)

This method is for internal use only.

object_id of the socket object used for this command.

Since:

  • 2.1.0

[ GitHub ]

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

attr_reader :socket_object_id

Instance Method Details

#command_summaryString (private)

Returns the command, formatted as a string, with automatically added keys elided ($clusterTime, lsid, signature).

Returns:

  • (String)

    The command summary.

Since:

  • 2.1.0

[ GitHub ]

  
# File 'lib/mongo/monitoring/event/command_started.rb', line 122

private def command_summary
  command = self.command
  remove_keys = %w($clusterTime lsid signature)
  if remove_keys.any? { |k| command.key?(k) }
    command = Hash[command.reject { |k, v| remove_keys.include?(k) }]
    suffix = ' ...'
  else
    suffix = ''
  end
  command.map do |k, v|
    "#{k}=#{v.inspect}"
  end.join(' ') + suffix
end

#inspectString

Returns a concise yet useful summary of the event.

Returns:

  • (String)

    String summary of the event.

Since:

  • 2.6.0

[ GitHub ]

  
# File 'lib/mongo/monitoring/event/command_started.rb', line 179

def inspect
  "#<{#{self.class} #{database_name}.#{command_name} command=#{command}>"
end

#summaryString

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_started.rb', line 114

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