module NewRelic::Agent::Datastores::Redis

Constants

ALL_BUT_FIRST
BINARY_DATA_PLACEHOLDER
CHUNK_SIZE
ELLIPSES
MAXIMUM_ARGUMENT_LENGTH
MAXIMUM_COMMAND_LENGTH
NEWLINE
OBFUSCATE_ARGS
PREFIX_RANGE
QUOTE
SPACE
STRINGS_SUPPORT_ENCODING
SUFFIX_RANGE

Public Class Methods

append_command_with_args(result, command_with_args) click to toggle source
# File lib/new_relic/agent/datastores/redis.rb, line 65
def self.append_command_with_args(result, command_with_args)
  result << command_with_args.first.to_s

  if command_with_args.size > 1
    command_with_args[ALL_BUT_FIRST].each do |arg|
      ellipsize(result, arg)

      break if result.length >= MAXIMUM_COMMAND_LENGTH
    end
  end

  result
end
append_command_with_no_args(result, command_with_args) click to toggle source
# File lib/new_relic/agent/datastores/redis.rb, line 79
def self.append_command_with_no_args(result, command_with_args)
  result << command_with_args.first.to_s
  result << OBFUSCATE_ARGS if command_with_args.size > 1
  result
end
append_pipeline_command(result, command_with_args) click to toggle source
# File lib/new_relic/agent/datastores/redis.rb, line 55
def self.append_pipeline_command(result, command_with_args)
  if Agent.config[:'transaction_tracer.record_redis_arguments']
    append_command_with_args(result, command_with_args)
  else
    append_command_with_no_args(result, command_with_args)
  end

  result
end
ellipsize(result, string) click to toggle source
# File lib/new_relic/agent/datastores/redis.rb, line 89
def self.ellipsize(result, string)
  result << SPACE
  if !string.is_a?(String)
    result << string.to_s
  elsif STRINGS_SUPPORT_ENCODING && string.encoding == Encoding::ASCII_8BIT
    result << BINARY_DATA_PLACEHOLDER
  elsif string.length > MAXIMUM_ARGUMENT_LENGTH
    result << QUOTE
    result << string[PREFIX_RANGE]
    result << ELLIPSES
    result << string[SUFFIX_RANGE]
    result << QUOTE
  else
    result << QUOTE
    result << string
    result << QUOTE
  end
end
format_command(command_with_args) click to toggle source
# File lib/new_relic/agent/datastores/redis.rb, line 26
def self.format_command(command_with_args)
  if Agent.config[:'transaction_tracer.record_redis_arguments']
    result = +''

    append_command_with_args(result, command_with_args)

    trim_result(result) if result.length >= MAXIMUM_COMMAND_LENGTH
    result.strip!
    result
  end
end
format_pipeline_commands(commands_with_args) click to toggle source
# File lib/new_relic/agent/datastores/redis.rb, line 38
def self.format_pipeline_commands(commands_with_args)
  result = +''

  commands_with_args.each do |command|
    if result.length >= MAXIMUM_COMMAND_LENGTH
      trim_result(result)
      break
    end

    append_pipeline_command(result, command)
    result << NEWLINE
  end

  result.strip!
  result
end
is_supported_version?() click to toggle source
# File lib/new_relic/agent/datastores/redis.rb, line 85
def self.is_supported_version?
  Gem::Version.new(::Redis::VERSION) >= Gem::Version.new('3.0.0')
end
safe_from_third_party_gem?() click to toggle source
# File lib/new_relic/agent/datastores/redis.rb, line 108
def self.safe_from_third_party_gem?
  if NewRelic::LanguageSupport.bundled_gem?('newrelic-redis')
    ::NewRelic::Agent.logger.info('Not installing New Relic supported Redis instrumentation because the third party newrelic-redis gem is present')
    false
  else
    true
  end
end
trim_result(result) click to toggle source
# File lib/new_relic/agent/datastores/redis.rb, line 117
def self.trim_result(result)
  result.slice!((MAXIMUM_COMMAND_LENGTH - ELLIPSES.length)..-1)
  result.strip!
  result << ELLIPSES
end