function getHostnameSafe(gcpId = null) {
  let _hostname
  const config = this
  this.getHostnameSafe = function getCachedHostname() {
    return _hostname
  }
  try {
    // Check for any special hostname scenarios.
    // If not applicable, use the os.hostname()
    if (config.heroku.use_dyno_names && process.env.DYNO) {
      _hostname = process.env.DYNO || os.hostname()
    } else if (config.gcp_cloud_run.use_instance_as_host && process.env.K_SERVICE && gcpId) {
      _hostname = gcpId
    } else {
      _hostname = os.hostname()
    }
    return _hostname
  } catch {
    const addresses = this.getIPAddresses()

    if (this.process_host.ipv_preference === '6' && addresses.ipv6) {
      _hostname = addresses.ipv6
    } else if (addresses.ipv4) {
      logger.info('Defaulting to ipv4 address for host name')
      _hostname = addresses.ipv4
    } else if (addresses.ipv6) {
      logger.info('Defaulting to ipv6 address for host name')
      _hostname = addresses.ipv6
    } else {
      logger.info('No hostname, ipv4, or ipv6 address found for machine')
      _hostname = 'UNKNOWN_BOX'
    }

    return _hostname
  }
}
Gets the system's host name. If that fails, it just returns ipv4/6
based on the user's process_host.ipv_preference setting.
@param {string} gcpId GCP metadata ID
@returns {string} host name