Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions lib/reporters/trace.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
var http = require('http');
var url = require('url');
var qs = require('qs');

var config = require('../config');

Expand Down Expand Up @@ -31,7 +30,8 @@ TraceReporter.prototype.send = function (data, callback) {
path: opts.path,
method: 'POST',
headers: {
'Authorization': 'Bearer ' + this.apiKey
'Authorization': 'Bearer ' + this.apiKey,
'Content-Type': 'application/json'
}
}, function () {
return callback(null);
Expand All @@ -40,7 +40,7 @@ TraceReporter.prototype.send = function (data, callback) {
return callback(err);
});

req.write(qs.stringify(data));
req.write(JSON.stringify(data));
req.end();
};

Expand All @@ -55,12 +55,19 @@ TraceReporter.prototype.getService = function(callback) {
path: opts.path,
method: 'POST',
headers: {
'Authorization': 'Bearer ' + this.apiKey
'Authorization': 'Bearer ' + this.apiKey,
'Content-Type': 'application/json'
}
}, function (res) {
res.setEncoding('utf8');
res.on('data', function (chunk) {
return callback(null, JSON.parse(chunk));
var res;
try {
res = JSON.parse(chunk);
} catch (ex) {
return callback(ex);
}
return callback(null, res);
});
})
.on('error', function (err) {
Expand All @@ -71,7 +78,7 @@ TraceReporter.prototype.getService = function(callback) {
}
});

req.write(qs.stringify({
req.write(JSON.stringify({
name: _this.appName
}));
req.end();
Expand Down
11 changes: 6 additions & 5 deletions lib/reporters/trace.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ var TraceReporter = require('./trace');

var expect = require('chai').expect;
var nock = require('nock');
var qs = require('qs');

var config = require('../config');

Expand Down Expand Up @@ -65,10 +64,11 @@ describe('The Trace reporter module', function () {

nock(collectorApi, {
reqheaders: {
'Authorization': 'Bearer testApiKey'
'Authorization': 'Bearer testApiKey',
'Content-Type': 'application/json'
}
})
.post(collectorApiSampleEndpoint, qs.stringify(data))
.post(collectorApiSampleEndpoint, JSON.stringify(data))
.reply(201);

var traceReporter = TraceReporter.create(options);
Expand All @@ -91,10 +91,11 @@ describe('The Trace reporter module', function () {

nock(collectorApi, {
reqheaders: {
'Authorization': 'Bearer testApiKey'
'Authorization': 'Bearer testApiKey',
'Content-Type': 'application/json'
}
})
.post(collectorApiServiceEndpoint, qs.stringify(data))
.post(collectorApiServiceEndpoint, JSON.stringify(data))
.reply(201, {
key: 1
});
Expand Down