Module: OpenTelemetry::Instrumentation::Utils

Extended by:
Utils
Included in:
Utils
Defined in:
lib/opentelemetry/instrumentation/dalli/utils.rb

Overview

Utility functions

Constant Summary collapse

STRING_PLACEHOLDER =
''.encode(::Encoding::UTF_8).freeze
CMD_MAX_LEN =
500
OPNAME_MAPPING =
{
  'get' => 'get',
  'cas' => 'get',
  'set' => 'set',
  'add' => 'add',
  'replace' => 'replace',
  'delete' => 'delete',
  'incr' => 'incr',
  'decr' => 'decr',
  'flush' => 'flush',
  'write_noop' => 'noop',
  'version' => 'version',
  'send_multiget' => 'getkq',
  'append' => 'append',
  'prepend' => 'prepend',
  'stats' => 'stat',
  'reset_stats' => 'stat',
  'multi_set' => 'setq',
  'multi_add' => 'addq',
  'multi_replace' => 'replaceq',
  'multi_delete' => 'deleteq',
  'touch' => 'touch'
  # 'sasl_authentication' => 'auth_negotiation',
  # 'sasl_authentication' => 'auth_request',
}.freeze

Instance Method Summary collapse

Instance Method Details

#format_command(operation, args) ⇒ Object



47
48
49
50
51
52
53
54
55
# File 'lib/opentelemetry/instrumentation/dalli/utils.rb', line 47

def format_command(operation, args)
  placeholder = "#{operation} BLOB (OMITTED)"
  command = [operation, *args].join(' ').strip
  command = OpenTelemetry::Common::Utilities.utf8_encode(command, binary: true, placeholder: placeholder)
  OpenTelemetry::Common::Utilities.truncate(command, CMD_MAX_LEN)
rescue StandardError => e
  OpenTelemetry.logger.debug("Error sanitizing Dalli operation: #{e}")
  placeholder
end

#opname(operation, multi) ⇒ Object



42
43
44
45
# File 'lib/opentelemetry/instrumentation/dalli/utils.rb', line 42

def opname(operation, multi)
  lookup_name = multi ? "multi_#{operation}" : operation.to_s
  OPNAME_MAPPING[lookup_name] || operation.to_s
end