class Sentry::Redis

@api private

def commands_description

def commands_description
  parsed_commands.map do |statement|
    statement.values.join(" ").strip
  end.join(", ")
end

def initialize(commands, host, port, db)

def initialize(commands, host, port, db)
  @commands, @host, @port, @db = commands, host, port, db
end

def instrument

def instrument
  return yield unless Sentry.initialized?
  Sentry.with_child_span(op: OP_NAME, start_timestamp: Sentry.utc_now.to_f) do |span|
    yield.tap do
      record_breadcrumb
      if span
        span.set_description(commands_description)
        span.set_data(:server, server_description)
      end
    end
  end
end

def parsed_commands

def parsed_commands
  commands.map do |statement|
    command, key, *arguments = statement
    command_set = { command: command.to_s.upcase }
    command_set[:key] = key if Utils::EncodingHelper.valid_utf_8?(key)
    if Sentry.configuration.send_default_pii
      command_set[:arguments] = arguments
                                .select { |a| Utils::EncodingHelper.valid_utf_8?(a) }
                                .join(" ")
    end
    command_set
  end
end

def record_breadcrumb

def record_breadcrumb
  return unless Sentry.initialized?
  return unless Sentry.configuration.breadcrumbs_logger.include?(LOGGER_NAME)
  Sentry.add_breadcrumb(
    Sentry::Breadcrumb.new(
      level: :info,
      category: OP_NAME,
      type: :info,
      data: {
        commands: parsed_commands,
        server: server_description
      }
    )
  )
end

def server_description

def server_description
  "#{host}:#{port}/#{db}"
end