Skip to content

Commit ccb38cf

Browse files
authored
feat: log non-standard ports in breadcrumbs (#440)
1 parent 9a6f62a commit ccb38cf

File tree

2 files changed

+63
-5
lines changed

2 files changed

+63
-5
lines changed

lib/instrumentation/http.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,16 @@ module.exports = function(Raven, http, originals) {
1919
if (typeof options === 'string') {
2020
this.__ravenBreadcrumbUrl = options;
2121
} else {
22-
this.__ravenBreadcrumbUrl =
23-
(options.protocol || '') +
24-
'//' +
25-
(options.hostname || options.host || '') +
26-
(options.path || '/');
22+
var protocol = options.protocol || '';
23+
var hostname = options.hostname || options.host || '';
24+
// Don't log standard :80 (http) and :443 (https) ports to reduce the noise
25+
var port =
26+
!options.port || options.port === 80 || options.port === 443
27+
? ''
28+
: ':' + options.port;
29+
var path = options.path || '/';
30+
31+
this.__ravenBreadcrumbUrl = protocol + '//' + hostname + port + path;
2732
}
2833
};
2934
util.inherits(ClientRequest, OrigClientRequest);

test/raven.client.js

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1444,6 +1444,33 @@ describe('raven.Client', function() {
14441444
});
14451445
});
14461446

1447+
it('should instrument http and log non-standard http (:80) port', function(done) {
1448+
var testUrl = 'http://example.com:1337/';
1449+
var scope = nock(testUrl)
1450+
.get('/')
1451+
.reply(200, 'OK');
1452+
1453+
client.context(function() {
1454+
var http = require('http');
1455+
http.get(url.parse(testUrl), function(response) {
1456+
response._readableState.should.have.property('flowing', initialFlowingState);
1457+
// need to wait a tick here because nock will make this callback fire
1458+
// before our req.emit monkeypatch captures the breadcrumb :/
1459+
setTimeout(function() {
1460+
response._readableState.should.have.property(
1461+
'flowing',
1462+
initialFlowingState
1463+
);
1464+
client.getContext().breadcrumbs[0].data.url.should.equal(testUrl);
1465+
client.getContext().breadcrumbs[0].data.status_code.should.equal(200);
1466+
client.getContext().breadcrumbs.length.should.equal(1);
1467+
scope.done();
1468+
done();
1469+
}, 0);
1470+
});
1471+
});
1472+
});
1473+
14471474
it('should instrument https to capture breadcrumbs', function(done) {
14481475
var testUrl = 'https://example.com/';
14491476
var scope = nock(testUrl)
@@ -1487,6 +1514,32 @@ describe('raven.Client', function() {
14871514
});
14881515
});
14891516
});
1517+
1518+
it('should instrument https and log non-standard https (:443) port', function(done) {
1519+
var testUrl = 'https://example.com:1337/';
1520+
var scope = nock(testUrl)
1521+
.get('/')
1522+
.reply(200, 'OK');
1523+
1524+
client.context(function() {
1525+
var https = require('https');
1526+
https.get(url.parse(testUrl), function(response) {
1527+
response._readableState.should.have.property('flowing', initialFlowingState);
1528+
// need to wait a tick here because nock will make this callback fire
1529+
// before our req.emit monkeypatch captures the breadcrumb :/
1530+
setTimeout(function() {
1531+
response._readableState.should.have.property(
1532+
'flowing',
1533+
initialFlowingState
1534+
);
1535+
client.getContext().breadcrumbs[0].data.url.should.equal(testUrl);
1536+
client.getContext().breadcrumbs[0].data.status_code.should.equal(200);
1537+
scope.done();
1538+
done();
1539+
}, 0);
1540+
});
1541+
});
1542+
});
14901543
});
14911544
});
14921545

0 commit comments

Comments
 (0)