Module: Datadog::Contrib::Redis::Quantize

Defined in:
lib/ddtrace/contrib/redis/quantize.rb

Overview

Quantize contains Redis-specific resource quantization tools.

Constant Summary collapse

PLACEHOLDER =
'?'.freeze
TOO_LONG_MARK =
'...'.freeze
VALUE_MAX_LEN =
50
CMD_MAX_LEN =
500

Class Method Summary collapse

Class Method Details

.format_arg(arg) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/ddtrace/contrib/redis/quantize.rb', line 13

def format_arg(arg)
  str = arg.is_a?(Symbol) ? arg.to_s.upcase : arg.to_s
  str = Utils.utf8_encode(str, binary: true, placeholder: PLACEHOLDER)
  Utils.truncate(str, VALUE_MAX_LEN, TOO_LONG_MARK)
rescue => e
  Datadog::Tracer.log.debug("non formattable Redis arg #{str}: #{e}")
  PLACEHOLDER
end

.format_command_args(command_args) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/ddtrace/contrib/redis/quantize.rb', line 22

def format_command_args(command_args)
  command_args = resolve_command_args(command_args)
  return 'AUTH ?' if auth_command?(command_args)

  cmd = command_args.map { |x| format_arg(x) }.join(' ')
  Utils.truncate(cmd, CMD_MAX_LEN, TOO_LONG_MARK)
end