Class: Appsignal::Hooks::MongoMonitorSubscriber

Inherits:
Object
  • Object
show all
Defined in:
lib/appsignal/integrations/mongo_ruby_driver.rb

Instance Method Summary collapse

Instance Method Details

#failed(event) ⇒ Object

Called by Mongo::Monitor when query fails


29
30
31
32
# File 'lib/appsignal/integrations/mongo_ruby_driver.rb', line 29

def failed(event)
  # Finish the event as failed
  finish('FAILED', event)
end

#finish(result, event) ⇒ Object

Finishes the event in the AppSignal extension


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/appsignal/integrations/mongo_ruby_driver.rb', line 35

def finish(result, event)
  transaction = Appsignal::Transaction.current
  return if transaction.nil_transaction?
  return if transaction.paused?

  # Get the query from the transaction store
  store   = transaction.store('mongo_driver')
  command = store.delete(event.request_id) || {}

  # Finish the event in the extension.
  transaction.finish_event(
    'query.mongodb',
    "#{event.command_name.to_s} | #{event.database_name} | #{result}",
    Appsignal::Utils.json_generate(command),
    0
  )
end

#started(event) ⇒ Object

Called by Mongo::Monitor when query starts


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/appsignal/integrations/mongo_ruby_driver.rb', line 5

def started(event)
  transaction = Appsignal::Transaction.current
  return if transaction.nil_transaction?
  return if transaction.paused?

  # Format the command
  command = Appsignal::EventFormatter::MongoRubyDriver::QueryFormatter
    .format(event.command_name, event.command)

  # Store the query on the transaction, we need it when the event finishes
  store                   = transaction.store('mongo_driver')
  store[event.request_id] = command

  # Start this event
  transaction.start_event
end

#succeeded(event) ⇒ Object

Called by Mongo::Monitor when query succeeds


23
24
25
26
# File 'lib/appsignal/integrations/mongo_ruby_driver.rb', line 23

def succeeded(event)
  # Finish the event as succeeded
  finish('SUCCEEDED', event)
end