Skip to content
This repository has been archived by the owner on Sep 13, 2022. It is now read-only.

Report HTTP errors when flushing spans #459

Merged
merged 2 commits into from
Apr 28, 2021
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
9 changes: 8 additions & 1 deletion src/reporters/http_sender.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,14 @@ export default class HTTPSender {
const req = requester(this._httpOptions, resp => {
// consume response data to free up memory
resp.resume();
SenderUtils.invokeCallback(callback, numSpans);

let error;
if (resp.statusCode >= 400) {
error = `error sending spans over HTTP: server responded with HTTP ${resp.statusCode}`;
this._logger.error(error);
}

SenderUtils.invokeCallback(callback, numSpans, error);
});

req.on('error', err => {
Expand Down
27 changes: 27 additions & 0 deletions test/http_sender.js
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,33 @@ describe('http sender', () => {
});
}).timeout(5000);

it('should log http errors when reporting', function(done) {
let loggedError = null;
const noop = () => {};
const logError = errMsg => {
loggedError = errMsg;
};

reporter = new InMemoryReporter();
tracer = new Tracer('test-service-name', reporter, new ConstSampler(true));
sender = new HTTPSender({
logger: { error: logError, info: noop },
endpoint: `http://localhost:${server.address().port}/404`,
maxSpanBatchSize: batchSize,
});
sender.setProcess(reporter._process);

let tracer = new Tracer('test-service-name', new RemoteReporter(sender), new ConstSampler(true));

tracer.startSpan('testSpan').finish();
sender.flush((numSpans, err) => {
assert.equal(numSpans, 1);
expect(err).to.have.string('error sending spans over HTTP: server responded with HTTP 404');
expect(loggedError).to.have.string('error sending spans over HTTP: server responded with HTTP 404');
tracer.close(done);
});
}).timeout(5000);

it('should handle HTTPS collectors', done => {
// Make it ignore the fact that our cert isn't valid.
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
Expand Down