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

Inherits:
Event::Base
  • Object
show all
Includes:
Secure
Defined in:
lib/mongo/monitoring/event/command_started.rb

Overview

Event that is fired when a command operation starts.

Since:

  • 2.1.0

Constant Summary

Constants included from Secure

Secure::REDACTED_COMMANDS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Secure

#compression_allowed?, #redacted, #sensitive?

Constructor Details

#initialize(command_name, database_name, address, request_id, operation_id, command, socket_object_id: nil, connection_id: nil, connection_generation: nil, server_connection_id: nil, service_id: nil) ⇒ CommandStarted

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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.

  • command (BSON::Document)

    The command arguments.

  • service_id (Object) (defaults to: nil)

    The service id, if any.

Since:

  • 2.1.0



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/mongo/monitoring/event/command_started.rb', line 83

def initialize(command_name, database_name, address, request_id,
               operation_id, command, socket_object_id: nil, connection_id: nil,
               connection_generation: nil, server_connection_id: nil,
               service_id: nil)
  @command_name = command_name.to_s
  @database_name = database_name
  @address = address
  @request_id = request_id
  @operation_id = operation_id
  @service_id = service_id
  @sensitive = sensitive?(
    command_name: @command_name,
    document: command
  )
  @command = redacted(command_name, command)
  @socket_object_id = socket_object_id
  @connection_id = connection_id
  @connection_generation = connection_generation
  @server_connection_id = server_connection_id
end

Instance Attribute Details

#addressServer::Address (readonly)

Returns address The server address.

Returns:

  • (Server::Address)

    address The server address.

Since:

  • 2.1.0



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

def address
  @address
end

#commandBSON::Document (readonly)

Returns command The command arguments.

Returns:

  • (BSON::Document)

    command The command arguments.

Since:

  • 2.1.0



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

def command
  @command
end

#command_nameString (readonly)

Returns command_name The name of the command.

Returns:

  • (String)

    command_name The name of the command.

Since:

  • 2.1.0



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

def command_name
  @command_name
end

#connection_generationObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Since:

  • 2.1.0



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

def connection_generation
  @connection_generation
end

#connection_idInteger (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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

Returns:

  • (Integer)

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

Since:

  • 2.1.0



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

def connection_id
  @connection_id
end

#database_nameString (readonly)

Returns database_name The name of the database_name.

Returns:

  • (String)

    database_name The name of the database_name.

Since:

  • 2.1.0



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

def database_name
  @database_name
end

#operation_idInteger (readonly)

Returns operation_id The operation id.

Returns:

  • (Integer)

    operation_id The operation id.

Since:

  • 2.1.0



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

def operation_id
  @operation_id
end

#request_idInteger (readonly)

Returns request_id The request id.

Returns:

  • (Integer)

    request_id The request id.

Since:

  • 2.1.0



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

def request_id
  @request_id
end

#sensitivetrue | false (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns Whether the event contains sensitive data.

Returns:

  • (true | false)

    Whether the event contains sensitive data.

Since:

  • 2.1.0



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

def sensitive
  @sensitive
end

#server_connection_idInteger (readonly)

Returns server_connection_id The server connection id.

Returns:

  • (Integer)

    server_connection_id The server connection id.

Since:

  • 2.1.0



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

def server_connection_id
  @server_connection_id
end

#service_idnil | Object (readonly)

Returns The service id, if any.

Returns:

  • (nil | Object)

    The service id, if any.

Since:

  • 2.1.0



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

def service_id
  @service_id
end

#socket_object_idObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

object_id of the socket object used for this command.

Since:

  • 2.1.0



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

def socket_object_id
  @socket_object_id
end

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 part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

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) (defaults to: nil)

    The service id, if any.

Returns:

Since:

  • 2.1.0



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/mongo/monitoring/event/command_started.rb', line 147

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 Method Details

#inspectString

Returns a concise yet useful summary of the event.

Returns:

  • (String)

    String summary of the event.

Since:

  • 2.6.0



175
176
177
# File 'lib/mongo/monitoring/event/command_started.rb', line 175

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



111
112
113
# File 'lib/mongo/monitoring/event/command_started.rb', line 111

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