Sha256: fbc1346297b0cbf12b212f2c549515af99b5e33a86fd4104a6463e765c80cf09

Contents?: true

Size: 1.53 KB

Versions: 31

Compression:

Stored size: 1.53 KB

Contents

# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/newrelic-ruby-agent/blob/main/LICENSE for complete details.
# frozen_string_literal: true

require_relative '../nosql_obfuscator'

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

          # Keys that will get completely removed from the statement.
          DENYLISTED_KEYS = %w[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 = NewRelic::Agent::Datastores::NosqlObfuscator.obfuscate_statement(statement)
            end
            statement
          end
        end
      end
    end
  end
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
newrelic_rpm-9.16.0 lib/new_relic/agent/datastores/mongo/event_formatter.rb
newrelic_rpm-9.15.0 lib/new_relic/agent/datastores/mongo/event_formatter.rb
newrelic_rpm-9.14.0 lib/new_relic/agent/datastores/mongo/event_formatter.rb
newrelic_rpm-9.13.0 lib/new_relic/agent/datastores/mongo/event_formatter.rb
newrelic_rpm-9.12.0 lib/new_relic/agent/datastores/mongo/event_formatter.rb
newrelic_rpm-9.11.0 lib/new_relic/agent/datastores/mongo/event_formatter.rb
newrelic_rpm-9.10.2 lib/new_relic/agent/datastores/mongo/event_formatter.rb
newrelic_rpm-9.10.1 lib/new_relic/agent/datastores/mongo/event_formatter.rb
newrelic_rpm-9.10.0 lib/new_relic/agent/datastores/mongo/event_formatter.rb
newrelic_rpm-9.9.0 lib/new_relic/agent/datastores/mongo/event_formatter.rb
newrelic_rpm-9.8.0 lib/new_relic/agent/datastores/mongo/event_formatter.rb
newrelic_rpm-9.7.1 lib/new_relic/agent/datastores/mongo/event_formatter.rb
newrelic_rpm-9.7.0 lib/new_relic/agent/datastores/mongo/event_formatter.rb
newrelic_rpm-9.6.0 lib/new_relic/agent/datastores/mongo/event_formatter.rb
newrelic_rpm-9.5.0 lib/new_relic/agent/datastores/mongo/event_formatter.rb
newrelic_rpm-9.4.2 lib/new_relic/agent/datastores/mongo/event_formatter.rb
newrelic_rpm-9.4.1 lib/new_relic/agent/datastores/mongo/event_formatter.rb
newrelic_rpm-9.4.0 lib/new_relic/agent/datastores/mongo/event_formatter.rb
newrelic_rpm-9.3.1 lib/new_relic/agent/datastores/mongo/event_formatter.rb
newrelic_rpm-9.3.0 lib/new_relic/agent/datastores/mongo/event_formatter.rb