Sha256: 1918948207c07fcd6a7228774c91c949e82e62ffc92b512ab3a1de5a265ee4c3

Contents?: true

Size: 1.51 KB

Versions: 7

Compression:

Stored size: 1.51 KB

Contents

# encoding: utf-8
# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
require 'new_relic/agent/datastores/mongo/obfuscator'

module NewRelic
  module Agent
    module Datastores
      module Mongo
        module EventFormatter
          # Keys that will get their values replaced with '?'.
          OBFUSCATE_KEYS = ['filter', 'query', 'pipeline'].freeze

          # Keys that will get completely removed from the statement.
          DENYLISTED_KEYS = ['deletes', 'documents', 'updates'].freeze

          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

          def self.obfuscate(statement)
            if NewRelic::Agent.config[:'mongo.obfuscate_queries']
              statement = Obfuscator.obfuscate_statement(statement)
            end
            statement
          end
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
newrelic_rpm-8.9.0 lib/new_relic/agent/datastores/mongo/event_formatter.rb
newrelic_rpm-8.8.0 lib/new_relic/agent/datastores/mongo/event_formatter.rb
newrelic_rpm-8.7.0 lib/new_relic/agent/datastores/mongo/event_formatter.rb
newrelic_rpm-8.6.0 lib/new_relic/agent/datastores/mongo/event_formatter.rb
newrelic_rpm-8.5.0 lib/new_relic/agent/datastores/mongo/event_formatter.rb
newrelic_rpm-8.4.0 lib/new_relic/agent/datastores/mongo/event_formatter.rb
newrelic_rpm-8.3.0 lib/new_relic/agent/datastores/mongo/event_formatter.rb