function initialize(config, { loggerInstance } = {}) {
  /**
   * When the logger is required here, it bootstraps itself and then
   * injects itself into this module's closure via setLogger on the
   * instance of the logger it creates.  Logs are queued until config
   * has been loaded to apply logging settings to bootstrapping logs
   */
  logger = loggerInstance ?? require('../logger')

  if (config) {
    return new Config(config)
  }

  if (isTruthular(process.env.NEW_RELIC_NO_CONFIG_FILE)) {
    logger.info('NEW_RELIC_NO_CONFIG_FILE set, deferring to environment variables.')

    return createNewConfigObject(config)
  }

  const filepath = _findConfigFile()
  if (!filepath) {
    logger.info(
      [
        'Unable to find configuration file.',
        'If a configuration file is desired (common for non-containerized environments),',
        `a base configuration file can be copied from ${BASE_CONFIG_PATH}`,
        'and renamed to "newrelic.js" in the directory from which you will start',
        'your application.',
        'Attempting to start agent using environment variables.'
      ].join(' ')
    )

    return createNewConfigObject(config)
  }

  let userConf
  try {
    userConf = require(filepath).config
  } catch (error) {
    if (error.code === 'ERR_REQUIRE_ESM') {
      // Attempted to import newrelic.js or similar from an ESM module, error out early.
      throw error
    }
    logger.error(error)

    logger.warn(
      [
        `Unable to read existing configuration file "${filepath}".`,
        'To allow reading of the file (if desired),',
        'please ensure the application has read access and the file is exporting valid JSON.',
        'Attempting to start agent using environment variables.'
      ].join(' ')
    )
  }

  if (!userConf) {
    return createNewConfigObject(config)
  }

  config = new Config(userConf)
  config.config_file_path = filepath
  logger.debug('Using configuration file %s.', filepath)

  config.validateFlags()

  return config
}
Create a configuration, either from a configuration file or the node
process's environment.

For configuration via file, check these directories, in order, for a
file named 'newrelic.js':

  1. The process's current working directory at startup.
  2. The same directory as the process's main module (i.e. the filename
     passed to node on the command line).
  3. The directory pointed to by the environment variable NEW_RELIC_HOME.
  4. The current process's HOME directory.
  5. If this module is installed as a dependency, the directory above the
     node_modules folder in which newrelic is installed.

When node process environment variables and a config file are used,
the environment variables will override their corresponding
configuration file settings.

@param {object} config Optional configuration to be used in place of a config file.
@param root0
@param root0.loggerInstance
@returns {object} instantiated configuration object