Class: BrainzLab::Instrumentation::MongoDBInstrumentation::CommandSubscriber

Inherits:
Object
  • Object
show all
Defined in:
lib/brainzlab/instrumentation/mongodb.rb

Overview

MongoDB Command Subscriber

Constant Summary collapse

SKIP_COMMANDS =
%w[isMaster ismaster buildInfo getLastError saslStart saslContinue].freeze

Instance Method Summary collapse

Constructor Details

#initializeCommandSubscriber

Returns a new instance of CommandSubscriber.



64
65
66
# File 'lib/brainzlab/instrumentation/mongodb.rb', line 64

def initialize
  @commands = {}
end

Instance Method Details

#failed(event) ⇒ Object

Called when command fails



86
87
88
# File 'lib/brainzlab/instrumentation/mongodb.rb', line 86

def failed(event)
  record_command(event, success: false, error: event.message)
end

#started(event) ⇒ Object

Called when command starts



69
70
71
72
73
74
75
76
77
78
# File 'lib/brainzlab/instrumentation/mongodb.rb', line 69

def started(event)
  return if skip_command?(event.command_name)

  @commands[event.request_id] = {
    started_at: Time.now.utc,
    command_name: event.command_name,
    database: event.database_name,
    collection: extract_collection(event)
  }
end

#succeeded(event) ⇒ Object

Called when command succeeds



81
82
83
# File 'lib/brainzlab/instrumentation/mongodb.rb', line 81

def succeeded(event)
  record_command(event, success: true)
end