fetchConfig()

in packages/rum-core/src/common/apm-server.js [177:218]


  fetchConfig(serviceName, environment) {
    var { configEndpoint } = this.getEndpoints()
    if (!serviceName) {
      return Promise.reject(
        'serviceName is required for fetching central config.'
      )
    }
    configEndpoint += `?service.name=${serviceName}`
    if (environment) {
      configEndpoint += `&service.environment=${environment}`
    }

    let localConfig = this._configService.getLocalConfig()
    if (localConfig) {
      configEndpoint += `&ifnonematch=${localConfig.etag}`
    }

    const apmRequest = this._configService.get('apmRequest')

    return this._makeHttpRequest('GET', configEndpoint, {
      timeout: 5000,
      beforeSend: apmRequest
    })
      .then(xhr => {
        const { status, responseText } = xhr
        if (status === 304) {
          return localConfig
        } else {
          let remoteConfig = JSON.parse(responseText)
          const etag = xhr.getResponseHeader('etag')
          if (etag) {
            remoteConfig.etag = etag.replace(/["]/g, '')
            this._configService.setLocalConfig(remoteConfig, true)
          }
          return remoteConfig
        }
      })
      .catch(reason => {
        const error = this._constructError(reason)
        return Promise.reject(error)
      })
  }