Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
feat: log non-standard ports in breadcrumbs (#440)
Browse files Browse the repository at this point in the history
  • Loading branch information
kamilogorek committed Apr 4, 2018
1 parent 9a6f62a commit ccb38cf
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 5 deletions.
15 changes: 10 additions & 5 deletions lib/instrumentation/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@ module.exports = function(Raven, http, originals) {
if (typeof options === 'string') {
this.__ravenBreadcrumbUrl = options;
} else {
this.__ravenBreadcrumbUrl =
(options.protocol || '') +
'//' +
(options.hostname || options.host || '') +
(options.path || '/');
var protocol = options.protocol || '';
var hostname = options.hostname || options.host || '';
// Don't log standard :80 (http) and :443 (https) ports to reduce the noise
var port =
!options.port || options.port === 80 || options.port === 443
? ''
: ':' + options.port;
var path = options.path || '/';

this.__ravenBreadcrumbUrl = protocol + '//' + hostname + port + path;
}
};
util.inherits(ClientRequest, OrigClientRequest);
Expand Down
53 changes: 53 additions & 0 deletions test/raven.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1444,6 +1444,33 @@ describe('raven.Client', function() {
});
});

it('should instrument http and log non-standard http (:80) port', function(done) {
var testUrl = 'http://example.com:1337/';
var scope = nock(testUrl)
.get('/')
.reply(200, 'OK');

client.context(function() {
var http = require('http');
http.get(url.parse(testUrl), function(response) {
response._readableState.should.have.property('flowing', initialFlowingState);
// need to wait a tick here because nock will make this callback fire
// before our req.emit monkeypatch captures the breadcrumb :/
setTimeout(function() {
response._readableState.should.have.property(
'flowing',
initialFlowingState
);
client.getContext().breadcrumbs[0].data.url.should.equal(testUrl);
client.getContext().breadcrumbs[0].data.status_code.should.equal(200);
client.getContext().breadcrumbs.length.should.equal(1);
scope.done();
done();
}, 0);
});
});
});

it('should instrument https to capture breadcrumbs', function(done) {
var testUrl = 'https://example.com/';
var scope = nock(testUrl)
Expand Down Expand Up @@ -1487,6 +1514,32 @@ describe('raven.Client', function() {
});
});
});

it('should instrument https and log non-standard https (:443) port', function(done) {
var testUrl = 'https://example.com:1337/';
var scope = nock(testUrl)
.get('/')
.reply(200, 'OK');

client.context(function() {
var https = require('https');
https.get(url.parse(testUrl), function(response) {
response._readableState.should.have.property('flowing', initialFlowingState);
// need to wait a tick here because nock will make this callback fire
// before our req.emit monkeypatch captures the breadcrumb :/
setTimeout(function() {
response._readableState.should.have.property(
'flowing',
initialFlowingState
);
client.getContext().breadcrumbs[0].data.url.should.equal(testUrl);
client.getContext().breadcrumbs[0].data.status_code.should.equal(200);
scope.done();
done();
}, 0);
});
});
});
});
});

Expand Down

0 comments on commit ccb38cf

Please sign in to comment.