Sha256: 93fe20347a1fdf8e3b3123618f830385cc4f8c4bd52b01640e462cfc17609562

Contents?: true

Size: 1.21 KB

Versions: 3

Compression:

Stored size: 1.21 KB

Contents

# 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::Agent.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::Agent.config[:'mongo.obfuscate_queries']
            statement
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
oneapm_rpm-1.1.2 lib/one_apm/agent/datastores/mongo/statement_formatter.rb
oneapm_rpm-1.1.1 lib/one_apm/agent/datastores/mongo/statement_formatter.rb
oneapm_rpm-1.1.0 lib/one_apm/agent/datastores/mongo/statement_formatter.rb