Skip to content

Commit 2bdfae6

Browse files
committed
fix(proxy): add http/https env var supports
1 parent 62eba47 commit 2bdfae6

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

lib/agent/api/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ CollectorApi.prototype._send = function (destinationUrl, data, callback) {
101101
debug('sending data to trace servers: ', destinationUrl, payload)
102102

103103
req.on('error', function (error) {
104-
console.error('error: [trace]', 'There was an error connecting to the Trace servers. Make sure your servers can reach', opts.hostname)
104+
console.error('error: [trace]', 'There was an error connecting to the Trace servers when sending data. Make sure your servers can reach', opts.hostname)
105105
debug('error connecting to the Trace servers', error)
106106
callback(error)
107107
})
@@ -274,6 +274,7 @@ CollectorApi.prototype.getService = function (cb) {
274274
hostname: opts.hostname,
275275
port: opts.port,
276276
path: opts.path,
277+
agent: this.proxyAgent,
277278
method: 'POST',
278279
headers: {
279280
'Authorization': 'Bearer ' + this.apiKey,
@@ -321,7 +322,7 @@ CollectorApi.prototype.getService = function (cb) {
321322
debug('getting serviceKey with payload:', payload)
322323

323324
req.on('error', function (error) {
324-
console.error('error: [trace]', 'There was an error connecting to the Trace servers. Make sure your servers can reach', opts.hostname)
325+
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)
325326
debug('error connecting to the Trace servers', error)
326327
})
327328
req.write(payload)

lib/agent/api/index.spec.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,17 @@ describe('The Trace CollectorApi module', function () {
8484
expect(collectorApi.proxyAgent).to.be.ok
8585
})
8686

87+
it('can use a proxy to get the service key', function () {
88+
var httpsRequestSpy = this.sandbox.spy(https, 'request')
89+
defaultConfig.proxy = 'http://127.0.0.1'
90+
91+
var collectorApi = CollectorApi.create(defaultConfig)
92+
93+
collectorApi.getService()
94+
expect(httpsRequestSpy.firstCall.args[0].agent).to.eql(collectorApi.proxyAgent)
95+
expect(collectorApi.proxyAgent).to.be.ok
96+
})
97+
8798
it('sends rpm metrics to the collector server', function () {
8899
var serviceKey = 12
89100

lib/utils/configReader.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ ConfigReader.prototype._getEnvVarConfig = function () {
6363
disableInstrumentations: process.env.TRACE_DISABLE_INSTRUMENTATIONS
6464
? process.env.TRACE_DISABLE_INSTRUMENTATIONS.split(',')
6565
: undefined,
66-
proxy: process.env.TRACE_PROXY || process.env.HTTP_PROXY
66+
proxy: process.env.TRACE_PROXY || process.env.HTTPS_PROXY || process.env.https_proxy || process.env.HTTP_PROXY
6767
}
6868

6969
var ignoreHeaders

0 commit comments

Comments
 (0)