Class: Appsignal::Hooks::MongoMonitorSubscriber Private

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

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

Instance Method Summary collapse

Instance Method Details

#failed(event) ⇒ Object

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.

Called by Mongo::Monitor when query fails



33
34
35
36
# File 'lib/appsignal/integrations/mongo_ruby_driver.rb', line 33

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

#finish(result, event) ⇒ Object

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.

Finishes the event in the AppSignal extension



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/appsignal/integrations/mongo_ruby_driver.rb', line 39

def finish(result, event)
  return unless Appsignal::Transaction.current?

  transaction = Appsignal::Transaction.current
  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} | #{event.database_name} | #{result}",
    Appsignal::Utils::Data.generate(command),
    Appsignal::EventFormatter::DEFAULT
  )

  # Send global query metrics
  Appsignal.add_distribution_value(
    "mongodb_query_duration",
    event.duration,
    :database => event.database_name
  )
end

#started(event) ⇒ Object

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.

Called by Mongo::Monitor when query starts



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/appsignal/integrations/mongo_ruby_driver.rb', line 8

def started(event)
  return unless Appsignal::Transaction.current?

  transaction = Appsignal::Transaction.current
  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

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.

Called by Mongo::Monitor when query succeeds



27
28
29
30
# File 'lib/appsignal/integrations/mongo_ruby_driver.rb', line 27

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