Comparing version 1.1.2 to 1.1.3
@@ -0,1 +1,6 @@ | ||
# 1.1.3 - 2/27/2017 | ||
- Add `parseUser` option to control user parsing behavior [See #274] | ||
- Make http instrumentation use `req.emit` instead of response event handler [See #276] | ||
- Add alert about raven-node vs raven-js when it seems like a browser env [See #277] | ||
# 1.1.2 - 2/8/2017 | ||
@@ -2,0 +7,0 @@ - Send kwargs to `shouldSendCallback` [See #251] |
@@ -90,17 +90,18 @@ 'use strict'; | ||
if (!Raven.dsn || url.indexOf(Raven.dsn.host) === -1) { | ||
self.once('response', function (response) { | ||
Raven.captureBreadcrumb({ | ||
type: 'http', | ||
category: 'http', | ||
data: { | ||
method: method, | ||
url: url, | ||
status_code: response.statusCode | ||
fill(self, 'emit', function (origEmit) { | ||
return function (evt, maybeResp) { | ||
if (evt === 'response') { | ||
Raven.captureBreadcrumb({ | ||
type: 'http', | ||
category: 'http', | ||
data: { | ||
method: method, | ||
url: url, | ||
status_code: maybeResp.statusCode | ||
} | ||
}); | ||
} | ||
}); | ||
// No-op to consume response data since we added a response handler | ||
// see https://nodejs.org/api/http.html#http_class_http_clientrequest | ||
response.on('data', function () {}); | ||
}); | ||
return origEmit.apply(this, arguments); | ||
}; | ||
}, originals); | ||
} | ||
@@ -107,0 +108,0 @@ }; |
@@ -26,2 +26,7 @@ 'use strict'; | ||
config: function config(dsn, options) { | ||
// We get lots of users using raven-node when they want raven-js, hence this warning if it seems like a browser | ||
if (typeof window !== 'undefined' && typeof document !== 'undefined' && typeof navigator !== 'undefined') { | ||
utils.consoleAlert('This looks like a browser environment; are you sure you don\'t want Raven.js for browser JavaScript? https://sentry.io/for/javascript'); | ||
} | ||
if (arguments.length === 0) { | ||
@@ -75,2 +80,3 @@ // no arguments, use default from environment | ||
this.shouldSendCallback = options.shouldSendCallback; | ||
this.parseUser = options.parseUser; | ||
@@ -412,3 +418,3 @@ if (!this.dsn) { | ||
var kwargs = parsers.parseRequest(req); | ||
var kwargs = parsers.parseRequest(req, self.parseUser); | ||
var eventId = self.captureException(err, kwargs); | ||
@@ -415,0 +421,0 @@ res.sentry = eventId; |
@@ -56,70 +56,44 @@ 'use strict'; | ||
module.exports.parseRequest = function parseRequest(req, kwargs) { | ||
kwargs = kwargs || {}; | ||
module.exports.parseRequest = function parseRequest(req, parseUser) { | ||
var kwargs = {}; | ||
// headers: | ||
// | ||
// node: req.headers | ||
// express: req.headers | ||
// node, express: req.headers | ||
// koa: req.header | ||
// | ||
var headers = req.headers || req.header || {}; | ||
// method: | ||
// | ||
// node: req.method | ||
// express: req.method | ||
// koa: req.method | ||
// | ||
// node, express, koa: req.method | ||
var method = req.method; | ||
// host: | ||
// | ||
// node: req.headers.host | ||
// express: req.hostname in > 4 and req.host in < 4 | ||
// koa: req.host | ||
// | ||
// node: req.headers.host | ||
var host = req.hostname || req.host || headers.host || '<no host>'; | ||
// protocol: | ||
// | ||
// node: <n/a> | ||
// express: req.protocol | ||
// koa: req.protocol | ||
// | ||
// express, koa: req.protocol | ||
var protocol = req.protocol === 'https' || req.secure || (req.socket || {}).encrypted ? 'https' : 'http'; | ||
// url (including path and query string): | ||
// | ||
// node: req.originalUrl | ||
// express: req.originalUrl | ||
// node, express: req.originalUrl | ||
// koa: req.url | ||
// | ||
var originalUrl = req.originalUrl || req.url; | ||
// absolute url | ||
var url = protocol + '://' + host + originalUrl; | ||
var absoluteUrl = protocol + '://' + host + originalUrl; | ||
// query string | ||
// | ||
// query string: | ||
// node: req.url (raw) | ||
// express: req.query | ||
// koa: req.query | ||
// | ||
// express, koa: req.query | ||
var query = req.query || urlParser.parse(originalUrl || '', true).query; | ||
// cookies: | ||
// | ||
// node: req.headers.cookie | ||
// express: req.headers.cookie | ||
// koa: req.headers.cookie | ||
// | ||
// node, express, koa: req.headers.cookie | ||
var cookies = cookie.parse(headers.cookie || ''); | ||
// body data: | ||
// | ||
// node: req.body | ||
// express: req.body | ||
// koa: req.body | ||
// | ||
// node, express, koa: req.body | ||
var data = req.body; | ||
@@ -132,3 +106,3 @@ if (['GET', 'HEAD'].indexOf(method) === -1) { | ||
if (data && {}.toString.call(data) !== '[object String]') { | ||
if (data && typeof data !== 'string' && {}.toString.call(data) !== '[object String]') { | ||
// Make sure the request body is a string | ||
@@ -138,10 +112,2 @@ data = stringify(data); | ||
// client ip: | ||
// | ||
// node: req.connection.remoteAddress | ||
// express: req.ip | ||
// koa: req.ip | ||
// | ||
var ip = req.ip || (req.connection || {}).remoteAddress; | ||
// http interface | ||
@@ -154,3 +120,3 @@ var http = { | ||
data: data, | ||
url: url | ||
url: absoluteUrl | ||
}; | ||
@@ -161,18 +127,34 @@ | ||
// user | ||
// | ||
// typically found on req.user according to Express and Passport | ||
var user = {}; | ||
if (!kwargs.user) { | ||
if (req.user) { | ||
// shallow copy is okay because we are only modifying top-level | ||
// object (req.user) | ||
for (var key in req.user) { | ||
if ({}.hasOwnProperty.call(req.user, key)) { | ||
user[key] = req.user[key]; | ||
// user: typically found on req.user in express/passport patterns | ||
// five cases for parseUser value: | ||
// absent: grab only id, username, email from req.user | ||
// false: capture nothing | ||
// true: capture all keys from req.user | ||
// array: provided whitelisted keys to grab from req.user | ||
// function :: req -> user: custom parsing function | ||
if (parseUser == null) parseUser = ['id', 'username', 'email']; | ||
if (parseUser) { | ||
var user = {}; | ||
if (typeof parseUser === 'function') { | ||
user = parseUser(req); | ||
} else if (req.user) { | ||
if (parseUser === true) { | ||
for (var key in req.user) { | ||
if ({}.hasOwnProperty.call(req.user, key)) { | ||
user[key] = req.user[key]; | ||
} | ||
} | ||
} else { | ||
parseUser.forEach(function (fieldName) { | ||
if ({}.hasOwnProperty.call(req.user, fieldName)) { | ||
user[fieldName] = req.user[fieldName]; | ||
} | ||
}); | ||
} | ||
} | ||
// client ip: | ||
// node: req.connection.remoteAddress | ||
// express, koa: req.ip | ||
var ip = req.ip || req.connection && req.connection.remoteAddress; | ||
if (ip) { | ||
@@ -179,0 +161,0 @@ user.ip_address = ip; |
@@ -12,3 +12,3 @@ { | ||
], | ||
"version": "1.1.2", | ||
"version": "1.1.3", | ||
"repository": "git://github.com/getsentry/raven-node.git", | ||
@@ -48,4 +48,4 @@ "author": "Matt Robenolt <matt@ydekproductions.com>", | ||
"nock": "~9.0.0", | ||
"should": "~3.3.1" | ||
"should": "11.2.0" | ||
} | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
364069
1497