class Labkit::Tracing::Redis::RedisInterceptorHelper
RedisInterceptorHelper
is a helper for the RedisInterceptor
. This is not a public API
Constants
- MASK_REDIS_RE
For optimization, compile this once
Public Class Methods
call_pipeline_with_tracing(pipeline, client) { || ... }
click to toggle source
# File lib/labkit/tracing/redis/redis_interceptor_helper.rb, line 19 def self.call_pipeline_with_tracing(pipeline, client) Labkit::Tracing::TracingUtils.with_tracing(operation_name: "redis.call_pipeline", tags: tags_from_pipeline(pipeline, client)) do |_span| yield end end
call_with_tracing(command, client) { || ... }
click to toggle source
# File lib/labkit/tracing/redis/redis_interceptor_helper.rb, line 13 def self.call_with_tracing(command, client) Labkit::Tracing::TracingUtils.with_tracing(operation_name: "redis.call", tags: tags_from_command(command, client)) do |_span| yield end end
command_is?(command_name, command_symbol)
click to toggle source
Returns true if the command is equivalent to the command_symbol symbol
# File lib/labkit/tracing/redis/redis_interceptor_helper.rb, line 90 def self.command_is?(command_name, command_symbol) if command_name.is_a?(Symbol) command_name == command_symbol else command_name.to_s.casecmp(command_symbol.to_s).zero? end end
command_is_sensitive?(command_name)
click to toggle source
Returns true if the arguments for the command should be masked
# File lib/labkit/tracing/redis/redis_interceptor_helper.rb, line 85 def self.command_is_sensitive?(command_name) command_is?(command_name, :auth) || command_is?(command_name, :eval) end
command_serialized(command)
click to toggle source
# File lib/labkit/tracing/redis/redis_interceptor_helper.rb, line 44 def self.command_serialized(command) return "" unless command.is_a?(Array) return "" if command.empty? command_name, *arguments = command command_name ||= "nil" info = [command_name] info << sanitize_argument_for_command(command_name, arguments.first) unless arguments.empty? info << "...#{arguments.size - 1} more value(s)" if arguments.size > 1 info.join(" ") end
sanitize_argument_for_command(command_name, first_argument)
click to toggle source
get_first_argument_for_command returns a masked value representing the first argument from a redis command, taking care of certain sensitive commands
# File lib/labkit/tracing/redis/redis_interceptor_helper.rb, line 74 def self.sanitize_argument_for_command(command_name, first_argument) return "*****" if command_is_sensitive?(command_name) return "nil" if first_argument.nil? return first_argument if first_argument.is_a?(Numeric) return "*****" unless first_argument.is_a?(String) mask_redis_arg(first_argument) end
Private Class Methods
mask_redis_arg(argument)
click to toggle source
# File lib/labkit/tracing/redis/redis_interceptor_helper.rb, line 98 def self.mask_redis_arg(argument) return "" if argument.empty? matches = argument.match(MASK_REDIS_RE) matches[2].empty? ? matches[0] : matches[0] + "*****" end