Skip to content

Commit

Permalink
fix(proxy): add http/https env var supports
Browse files Browse the repository at this point in the history
  • Loading branch information
gergelyke committed Nov 16, 2016
1 parent 62eba47 commit 2bdfae6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
5 changes: 3 additions & 2 deletions lib/agent/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
11 changes: 11 additions & 0 deletions lib/agent/api/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/utils/configReader.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

This comment has been minimized.

Copy link
@paul-cla

paul-cla Nov 17, 2016

probably needs one more || process.env.http_proxy on the end, as environment variables are case sensitive and for some reason, people use both variants of case.

This comment has been minimized.

Copy link
@gergelyke

gergelyke Nov 17, 2016

Author Contributor

good catch, thanks Paul!

}

var ignoreHeaders
Expand Down

0 comments on commit 2bdfae6

Please sign in to comment.