module NewRelic::Agent::Instrumentation::Mongodb

Public Instance Methods

logging_with_newrelic_trace(messages, operation_id = nil) click to toggle source
# File lib/newrelic_mongodb/instrumentation.rb, line 29
def logging_with_newrelic_trace(messages, operation_id = nil)
  operation_name, collection_name = determine_operation_and_collection(messages.first)

  NewRelic::Agent::Datastores.wrap('MongoDB', operation_name, collection_name, ->(result, metric, elapsed){ NewRelic::Agent::Datastores.notice_statement(operation_name, elapsed) }) do
    logging_without_newrelic_trace(messages, operation_id)
  end
end

Private Instance Methods

determine_operation_and_collection(message) click to toggle source
# File lib/newrelic_mongodb/instrumentation.rb, line 38
def determine_operation_and_collection(message)
  operation_name = message.payload[:command_name]

  collection_name = if message.respond_to?(:namespace) && (namespace_name = message.namespace.split('.').last) == '$cmd'
    message.selector[operation_name]
  else
    namespace_name
  end

  [operation_name, collection_name]
end