diff --git a/src/middleware/request.js b/src/middleware/request.js index 5583ae1..410546d 100644 --- a/src/middleware/request.js +++ b/src/middleware/request.js @@ -8,7 +8,7 @@ const _global = { } function handleResponse (span, status, err, msg) { - if (err || status >= 400) { + if (err instanceof Error || status >= 400) { // Error detected. Mark error, status code, and log error event span.setTag('error', true) if (status) span.setTag('http.status_code', status) diff --git a/test/request.spec.js b/test/request.spec.js index 871475a..6fbf087 100644 --- a/test/request.spec.js +++ b/test/request.spec.js @@ -15,6 +15,9 @@ function createServer () { req.on('end', () => { let path = urlParse(req.url).pathname let status = Number(path.split('?')[0].split('/')[1]) + if (req.headers && req.headers['content-type'] === 'application/json'){ + b = JSON.parse(b) + } switch (status) { case 301: res.writeHead(301, { Location: '/200' }) @@ -146,6 +149,14 @@ describe('request', () => { }) }) + it('should not mark error on 200', () => { + return tr({ method: 'PUT', uri: `${s.url}/200`, json: true, body: {data: 'test data'} }) + .then(() => { + let rec = JSON.parse(buf[0]) + rec.tags.should.not.have.property('error') + }) + }) + it('should mark http.status_code on 400', () => { return tr({ method: 'GET', uri: `${s.url}/400`, json: true }) .catch(() => {