module NewRelic::Agent::Datastores::Mongo::EventFormatter

Constants

DENYLISTED_KEYS

Keys that will get completely removed from the statement.

OBFUSCATE_KEYS

Keys that will get their values replaced with ‘?’.

Public Class Methods

format(command_name, database_name, command) click to toggle source
# File lib/new_relic/agent/datastores/mongo/event_formatter.rb, line 18
def self.format(command_name, database_name, command)
  return nil unless NewRelic::Agent.config[:'mongo.capture_queries']

  result = {
    :operation => command_name,
    :database => database_name,
    :collection => command.values.first
  }

  command.each do |key, value|
    next if DENYLISTED_KEYS.include?(key)

    if OBFUSCATE_KEYS.include?(key)
      obfuscated = obfuscate(value)
      result[key] = obfuscated if obfuscated
    else
      result[key] = value
    end
  end
  result
end
obfuscate(statement) click to toggle source
# File lib/new_relic/agent/datastores/mongo/event_formatter.rb, line 40
def self.obfuscate(statement)
  if NewRelic::Agent.config[:'mongo.obfuscate_queries']
    statement = NewRelic::Agent::Datastores::NosqlObfuscator.obfuscate_statement(statement)
  end
  statement
end