Module: NewRelic::Agent::Datastores::Redis

Defined in:
lib/new_relic/agent/datastores/redis.rb

Constant Summary collapse

BINARY_DATA_PLACEHOLDER =
'<binary data>'
MAXIMUM_COMMAND_LENGTH =
1000
MAXIMUM_ARGUMENT_LENGTH =
64
CHUNK_SIZE =
(MAXIMUM_ARGUMENT_LENGTH - 5) / 2
PREFIX_RANGE =
(0...CHUNK_SIZE)
SUFFIX_RANGE =
(-CHUNK_SIZE..-1)
OBFUSCATE_ARGS =
' ?'
ELLIPSES =
'...'
NEWLINE =
"\n"
SPACE =
' '
QUOTE =
'"'
ALL_BUT_FIRST =
(1..-1)
STRINGS_SUPPORT_ENCODING =
SPACE.respond_to?(:encoding)

Class Method Summary collapse

Class Method Details

.append_command_with_args(result, command_with_args) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
# 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) ⇒ Object



79
80
81
82
83
# 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) ⇒ Object



55
56
57
58
59
60
61
62
63
# 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) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# 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) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# 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) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# 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?Boolean

Returns:

  • (Boolean)


85
86
87
# 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?Boolean

Returns:

  • (Boolean)


108
109
110
111
112
113
114
115
# 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) ⇒ Object



117
118
119
120
121
# 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