# encoding: utf-8 require 'one_apm/agent/datastores/mongo/obfuscator' module OneApm module Agent module Datastores module Mongo module StatementFormatter PLAINTEXT_KEYS = [ :database, :collection, :operation, :fields, :skip, :limit, :order ] OBFUSCATE_KEYS = [ :selector ] def self.format(statement, operation) return nil unless OneApm::Manager.config[:'mongo.capture_queries'] result = { :operation => operation } PLAINTEXT_KEYS.each do |key| result[key] = statement[key] if statement.key?(key) end OBFUSCATE_KEYS.each do |key| if statement.key?(key) && statement[key] obfuscated = obfuscate(statement[key]) result[key] = obfuscated if obfuscated end end result end def self.obfuscate(statement) statement = Obfuscator.obfuscate_statement(statement) if OneApm::Manager.config[:'mongo.obfuscate_queries'] statement end end end end end end