Skip to content

Commit d1f4554

Browse files
Peter Martonhekike
authored andcommitted
feat(agent): send User-Agent
1 parent 13459ea commit d1f4554

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

lib/agent/api/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ var BufferStream = require('./bufferStream')
1414
var bl = require('bl')
1515
var libPackage = require('../../../package')
1616
var zlib = require('zlib')
17+
var userAgent = 'trace/' + libPackage.version
1718

1819
function CollectorApi (options) {
1920
this.COLLECTOR_API_SERVICE = url.resolve(options.collectorApiUrl, options.collectorApiServiceEndpoint)
@@ -49,7 +50,8 @@ CollectorApi.prototype._sendSync = function (destinationUrl, data, options) {
4950
'Authorization': 'Bearer ' + this.apiKey,
5051
'Content-Type': 'application/json',
5152
'X-Reporter-Version': libPackage.version,
52-
'X-Reporter-Language': this.collectorLanguage
53+
'X-Reporter-Language': this.collectorLanguage,
54+
'User-Agent': userAgent
5355
}, options && options.headers),
5456
timeout: 1000
5557
})
@@ -77,7 +79,8 @@ CollectorApi.prototype._send = function (destinationUrl, data, callback, options
7779
'Authorization': 'Bearer ' + this.apiKey,
7880
'Content-Type': 'application/json',
7981
'X-Reporter-Version': libPackage.version,
80-
'X-Reporter-Language': this.collectorLanguage
82+
'X-Reporter-Language': this.collectorLanguage,
83+
'User-Agent': userAgent
8184
}
8285

8386
assign(headers, options.headers)
@@ -281,7 +284,8 @@ CollectorApi.prototype.getService = function (cb) {
281284
'Content-Type': 'application/json',
282285
'X-Reporter-Version': libPackage.version,
283286
'X-Reporter-Language': this.collectorLanguage,
284-
'Content-Length': Buffer.byteLength(payload)
287+
'Content-Length': Buffer.byteLength(payload),
288+
'User-Agent': userAgent
285289
}
286290
}, function (res) {
287291
res.setEncoding('utf8')

lib/agent/api/index.spec.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,8 @@ describe('The Trace CollectorApi module', function () {
181181
'Authorization': 'Bearer testApiKey',
182182
'Content-Type': 'application/json',
183183
'X-Reporter-Version': libPackage.version,
184-
'X-Reporter-Language': defaultConfig.collectorLanguage
184+
'X-Reporter-Language': defaultConfig.collectorLanguage,
185+
'User-Agent': 'trace/' + libPackage.version
185186
}
186187
})
187188
.post(path, function (body) {
@@ -228,7 +229,8 @@ describe('The Trace CollectorApi module', function () {
228229
'Authorization': 'Bearer testApiKey',
229230
'Content-Type': 'application/json',
230231
'X-Reporter-Version': libPackage.version,
231-
'X-Reporter-Language': defaultConfig.collectorLanguage
232+
'X-Reporter-Language': defaultConfig.collectorLanguage,
233+
'User-Agent': 'trace/' + libPackage.version
232234
}
233235
})
234236
.post(defaultConfig.collectorApiServiceEndpoint, JSON.stringify(data))
@@ -271,7 +273,8 @@ describe('The Trace CollectorApi module', function () {
271273
'Authorization': 'Bearer testApiKey',
272274
'Content-Type': 'application/json',
273275
'X-Reporter-Version': libPackage.version,
274-
'X-Reporter-Language': defaultConfig.collectorLanguage
276+
'X-Reporter-Language': defaultConfig.collectorLanguage,
277+
'User-Agent': 'trace/' + libPackage.version
275278
}
276279
})
277280
.post(defaultConfig.collectorApiServiceEndpoint, JSON.stringify(data))

0 commit comments

Comments
 (0)