Skip to content

Commit

Permalink
add a test for the error annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-smith-zocdoc committed Jul 6, 2018
1 parent c0d9852 commit b706671
Showing 1 changed file with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,48 @@ describe('express middleware - integration test', () => {
});
});
});

it('should mark 500 respones as errors', done => {
const record = sinon.spy();
const recorder = {record};
const ctxImpl = new ExplicitContext();
const tracer = new Tracer({recorder, ctxImpl});

ctxImpl.scoped(() => {
const app = express();
app.use(middleware({
tracer,
serviceName: 'service-a'
}));
app.get('/error', (req, res) => {
tracer.recordBinary('message', 'hello from within app');
res.status(500).send({status: 'An Error Occurred'});
});
const server = app.listen(0, () => {
const port = server.address().port;
const urlPath = `http://127.0.0.1:${port}/error`;

fetch(urlPath, {
method: 'get'
}).then(res => {
server.close();

expect(res.status).to.equal(500);

const annotations = record.args.map(args => args[0]);

expect(annotations[6].annotation.key).to.equal('http.status_code');
expect(annotations[6].annotation.value).to.equal('500');
expect(annotations[7].annotation.key).to.equal('error');
expect(annotations[7].annotation.value).to.equal('500');

done();
})
.catch(err => {
server.close();
done(err);
});
});
});
});
});

0 comments on commit b706671

Please sign in to comment.