Skip to content

Commit

Permalink
feat(agent): send User-Agent
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Marton authored and hekike committed Sep 11, 2017
1 parent 13459ea commit d1f4554
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
10 changes: 7 additions & 3 deletions lib/agent/api/index.js
Expand Up @@ -14,6 +14,7 @@ var BufferStream = require('./bufferStream')
var bl = require('bl')
var libPackage = require('../../../package')
var zlib = require('zlib')
var userAgent = 'trace/' + libPackage.version

function CollectorApi (options) {
this.COLLECTOR_API_SERVICE = url.resolve(options.collectorApiUrl, options.collectorApiServiceEndpoint)
Expand Down Expand Up @@ -49,7 +50,8 @@ CollectorApi.prototype._sendSync = function (destinationUrl, data, options) {
'Authorization': 'Bearer ' + this.apiKey,
'Content-Type': 'application/json',
'X-Reporter-Version': libPackage.version,
'X-Reporter-Language': this.collectorLanguage
'X-Reporter-Language': this.collectorLanguage,
'User-Agent': userAgent
}, options && options.headers),
timeout: 1000
})
Expand Down Expand Up @@ -77,7 +79,8 @@ CollectorApi.prototype._send = function (destinationUrl, data, callback, options
'Authorization': 'Bearer ' + this.apiKey,
'Content-Type': 'application/json',
'X-Reporter-Version': libPackage.version,
'X-Reporter-Language': this.collectorLanguage
'X-Reporter-Language': this.collectorLanguage,
'User-Agent': userAgent
}

assign(headers, options.headers)
Expand Down Expand Up @@ -281,7 +284,8 @@ CollectorApi.prototype.getService = function (cb) {
'Content-Type': 'application/json',
'X-Reporter-Version': libPackage.version,
'X-Reporter-Language': this.collectorLanguage,
'Content-Length': Buffer.byteLength(payload)
'Content-Length': Buffer.byteLength(payload),
'User-Agent': userAgent
}
}, function (res) {
res.setEncoding('utf8')
Expand Down
9 changes: 6 additions & 3 deletions lib/agent/api/index.spec.js
Expand Up @@ -181,7 +181,8 @@ describe('The Trace CollectorApi module', function () {
'Authorization': 'Bearer testApiKey',
'Content-Type': 'application/json',
'X-Reporter-Version': libPackage.version,
'X-Reporter-Language': defaultConfig.collectorLanguage
'X-Reporter-Language': defaultConfig.collectorLanguage,
'User-Agent': 'trace/' + libPackage.version
}
})
.post(path, function (body) {
Expand Down Expand Up @@ -228,7 +229,8 @@ describe('The Trace CollectorApi module', function () {
'Authorization': 'Bearer testApiKey',
'Content-Type': 'application/json',
'X-Reporter-Version': libPackage.version,
'X-Reporter-Language': defaultConfig.collectorLanguage
'X-Reporter-Language': defaultConfig.collectorLanguage,
'User-Agent': 'trace/' + libPackage.version
}
})
.post(defaultConfig.collectorApiServiceEndpoint, JSON.stringify(data))
Expand Down Expand Up @@ -271,7 +273,8 @@ describe('The Trace CollectorApi module', function () {
'Authorization': 'Bearer testApiKey',
'Content-Type': 'application/json',
'X-Reporter-Version': libPackage.version,
'X-Reporter-Language': defaultConfig.collectorLanguage
'X-Reporter-Language': defaultConfig.collectorLanguage,
'User-Agent': 'trace/' + libPackage.version
}
})
.post(defaultConfig.collectorApiServiceEndpoint, JSON.stringify(data))
Expand Down

0 comments on commit d1f4554

Please sign in to comment.