diff --git a/lib/agent/api/index.js b/lib/agent/api/index.js index 1dcd811..1390d73 100644 --- a/lib/agent/api/index.js +++ b/lib/agent/api/index.js @@ -101,7 +101,7 @@ CollectorApi.prototype._send = function (destinationUrl, data, callback) { debug('sending data to trace servers: ', destinationUrl, payload) req.on('error', function (error) { - console.error('error: [trace]', 'There was an error connecting to the Trace servers. Make sure your servers can reach', opts.hostname) + console.error('error: [trace]', 'There was an error connecting to the Trace servers when sending data. Make sure your servers can reach', opts.hostname) debug('error connecting to the Trace servers', error) callback(error) }) @@ -274,6 +274,7 @@ CollectorApi.prototype.getService = function (cb) { hostname: opts.hostname, port: opts.port, path: opts.path, + agent: this.proxyAgent, method: 'POST', headers: { 'Authorization': 'Bearer ' + this.apiKey, @@ -321,7 +322,7 @@ CollectorApi.prototype.getService = function (cb) { debug('getting serviceKey with payload:', payload) req.on('error', function (error) { - console.error('error: [trace]', 'There was an error connecting to the Trace servers. Make sure your servers can reach', opts.hostname) + console.error('error: [trace]', 'There was an error connecting to the Trace servers to get the service key. Make sure your servers can reach', opts.hostname) debug('error connecting to the Trace servers', error) }) req.write(payload) diff --git a/lib/agent/api/index.spec.js b/lib/agent/api/index.spec.js index 9b53b76..22da635 100644 --- a/lib/agent/api/index.spec.js +++ b/lib/agent/api/index.spec.js @@ -84,6 +84,17 @@ describe('The Trace CollectorApi module', function () { expect(collectorApi.proxyAgent).to.be.ok }) + it('can use a proxy to get the service key', function () { + var httpsRequestSpy = this.sandbox.spy(https, 'request') + defaultConfig.proxy = 'http://127.0.0.1' + + var collectorApi = CollectorApi.create(defaultConfig) + + collectorApi.getService() + expect(httpsRequestSpy.firstCall.args[0].agent).to.eql(collectorApi.proxyAgent) + expect(collectorApi.proxyAgent).to.be.ok + }) + it('sends rpm metrics to the collector server', function () { var serviceKey = 12 diff --git a/lib/utils/configReader.js b/lib/utils/configReader.js index a1085db..078c8c9 100644 --- a/lib/utils/configReader.js +++ b/lib/utils/configReader.js @@ -63,7 +63,7 @@ ConfigReader.prototype._getEnvVarConfig = function () { disableInstrumentations: process.env.TRACE_DISABLE_INSTRUMENTATIONS ? process.env.TRACE_DISABLE_INSTRUMENTATIONS.split(',') : undefined, - proxy: process.env.TRACE_PROXY || process.env.HTTP_PROXY + proxy: process.env.TRACE_PROXY || process.env.HTTPS_PROXY || process.env.https_proxy || process.env.HTTP_PROXY } var ignoreHeaders