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

Methods inherited from Event::Base

#summary

Constructor Details

#initialize(command_name, database_name, address, request_id, operation_id, command, socket_object_id: nil, connection_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.


Since:

  • 2.1.0



67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/mongo/monitoring/event/command_started.rb', line 67

def initialize(command_name, database_name, address, request_id,
  operation_id, command, socket_object_id: nil, connection_id: nil
)
  @command_name = command_name.to_s
  @database_name = database_name
  @address = address
  @request_id = request_id
  @operation_id = operation_id
  @command = redacted(command_name, command)
  @socket_object_id = socket_object_id
  @connection_id = connection_id
end

Instance Attribute Details

#addressServer::Address (readonly)

Returns address The server address.

Since:

  • 2.1.0



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

def address
  @address
end

#commandBSON::Document (readonly)

Returns command The command arguments.

Since:

  • 2.1.0



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

def command
  @command
end

#command_nameString (readonly)

Returns command_name The name of the command.

Since:

  • 2.1.0



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

def command_name
  @command_name
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.

Since:

  • 2.1.0



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

def connection_id
  @connection_id
end

#database_nameString (readonly)

Returns database_name The name of the database_name.

Since:

  • 2.1.0



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

def database_name
  @database_name
end

#operation_idInteger (readonly)

Returns operation_id The operation id.

Since:

  • 2.1.0



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

def operation_id
  @operation_id
end

#request_idInteger (readonly)

Returns request_id The request id.

Since:

  • 2.1.0



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

def request_id
  @request_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



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

def socket_object_id
  @socket_object_id
end

Class Method Details

.generate(address, operation_id, payload, socket_object_id: nil, connection_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)

Since:

  • 2.1.0



93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/mongo/monitoring/event/command_started.rb', line 93

def self.generate(address, operation_id, payload,
  socket_object_id: nil, connection_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,
  )
end

Instance Method Details

#inspectString

Returns a concise yet useful summary of the event.

Since:

  • 2.6.0



118
119
120
# File 'lib/mongo/monitoring/event/command_started.rb', line 118

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