Comparing version 0.4.7 to 0.5.0
@@ -9,2 +9,6 @@ var parsers = require('./parsers'); | ||
var events = require('events'); | ||
var raw = require('raw-stacktrace'); | ||
var traces = raw({rawCallSites: true}); | ||
traces.setMaxListeners(100); | ||
traces.on("trace", function(err, callsites) {err.structuredStackTrace = callsites;}); | ||
@@ -30,12 +34,6 @@ module.exports.version = require('../package.json').version; | ||
this.loggerName = options.logger || ''; | ||
if(!this.dsn || !process.env.NODE_ENV || process.env.NODE_ENV !== 'production') { | ||
this._enabled = false; | ||
} else { | ||
this._enabled = true; | ||
} | ||
if(this.dsn && !this._enabled) { | ||
// we want to be silent only when FALSE is explicitly passed for a DSN value | ||
console.warn('Warning: Sentry logging is disabled, please set NODE_ENV=production'); | ||
} | ||
// enabled if a dsn is set | ||
this._enabled = !!this.dsn; | ||
this.on('error', function(e) {}); // noop | ||
@@ -163,6 +161,6 @@ }; | ||
client.once('logged', function() { | ||
cb(true); | ||
cb(true, err); | ||
}); | ||
client.once('error', function() { | ||
cb(false); | ||
cb(false, err); | ||
}); | ||
@@ -169,0 +167,0 @@ } |
@@ -10,13 +10,5 @@ var utils = require('./utils'); | ||
module.exports.parseError = function parseError(err, kwargs, cb) { | ||
var orig = Error.prepareStackTrace; | ||
Error.prepareStackTrace = function(_, stack) { return stack; }; | ||
// prepareStackTrace is triggered the first time .stack is accessed | ||
// so this is explicitly triggering it | ||
var stack = err.stack; | ||
// TODO: restore back an original style stack for anyone else that cares. | ||
Error.prepareStackTrace = orig; | ||
utils.parseStack(stack, function(frames) { | ||
err.stack; // Error.prepareStackTrace is only called when stack is accessed, so access it | ||
utils.parseStack(err.structuredStackTrace, function(frames) { | ||
kwargs['message'] = err.name + ': ' + (err.message || '<no message>'); | ||
@@ -27,5 +19,11 @@ kwargs['sentry.interfaces.Exception'] = { | ||
}; | ||
kwargs['sentry.interfaces.Stacktrace'] = {frames: frames}; | ||
for (var n = 0, l = frames.length; n < l; n++) { | ||
if (frames[n].in_app) { | ||
kwargs['culprit'] = frames[n].function; | ||
break; | ||
} | ||
} | ||
cb(kwargs); | ||
@@ -32,0 +30,0 @@ }); |
@@ -17,7 +17,7 @@ var events = require('events'); | ||
var options = { | ||
host: self.dsn.host, | ||
hostname: self.dsn.host, | ||
path: self.dsn.path + '/api/store/', | ||
headers: headers, | ||
method: 'POST', | ||
port: self.dsn.port | ||
port: self.dsn.port || this.defaultPort | ||
}, req = this.transport.request(options, function(res){ | ||
@@ -30,7 +30,7 @@ res.setEncoding('utf8'); | ||
res.on('end', function(){ | ||
if(res.statusCode === 200) { | ||
if(res.statusCode >= 200 && res.statusCode < 300) { | ||
self.emit('logged'); | ||
} else { | ||
body = body.join(''); | ||
var e = new Error('HTTP Error: ' + body); | ||
var e = new Error('HTTP Error (' + res.statusCode + '): ' + body); | ||
e.response = res; | ||
@@ -66,3 +66,3 @@ e.statusCode = res.statusCode; | ||
var udp = dgram.createSocket('udp4'); | ||
udp.send(message, 0, message.length, self.dsn.port, self.dsn.host, function(e, bytes) { | ||
udp.send(message, 0, message.length, self.dsn.port || this.defaultPort, self.dsn.host, function(e, bytes) { | ||
if(e){ | ||
@@ -69,0 +69,0 @@ return self.emit('error', e); |
@@ -91,12 +91,32 @@ var raven = require('./client'); | ||
function getFunction(line) { | ||
try { | ||
return line.getFunctionName() || | ||
line.getTypeName() + '.' + (line.getMethodName() || '<anonymous>'); | ||
} catch(e) { | ||
// This seems to happen sometimes when using 'use strict', | ||
// stemming from `getTypeName`. | ||
// [TypeError: Cannot read property 'constructor' of undefined] | ||
return '<anonymous>'; | ||
} | ||
} | ||
function parseStack(stack, cb) { | ||
var frames = [], | ||
cache = {}, | ||
callbacks = stack.length; | ||
callbacks; | ||
// check to make sure that the stack is what we need it to be. | ||
if (!stack || !Array.isArray(stack) || !stack.length || !stack[0].getFileName) { | ||
// lol, stack is fucked | ||
return cb(frames); | ||
} | ||
callbacks = stack.length; | ||
stack.forEach(function(line, index) { | ||
var frame = { | ||
filename: line.getFileName(), | ||
filename: line.getFileName() || '', | ||
lineno: line.getLineNumber(), | ||
'function': line.getFunctionName() || '?' | ||
'function': getFunction(line) | ||
}, isInternal = line.isNative() || | ||
@@ -106,4 +126,4 @@ (frame.filename[0] !== '/' && | ||
// in_app is either an internal Node function or a module within node_modules | ||
frame.in_app = isInternal || !!~frame.filename.indexOf('node_modules/'); | ||
// in_app is all that's not an internal Node function or a module within node_modules | ||
frame.in_app = !isInternal && !~frame.filename.indexOf('node_modules/'); | ||
@@ -110,0 +130,0 @@ // internal Node files are not full path names. Ignore them. |
@@ -5,3 +5,3 @@ { | ||
"keywords": ["raven", "sentry", "python"], | ||
"version": "0.4.7", | ||
"version": "0.5.0", | ||
"repository": "git://github.com/mattrobenolt/raven-node.git", | ||
@@ -18,3 +18,4 @@ "author": "Matt Robenolt <matt@ydekproductions.com>", | ||
"dependencies": { | ||
"node-uuid": "1.4.0" | ||
"node-uuid": "1.4.0", | ||
"raw-stacktrace": "0.0.2" | ||
}, | ||
@@ -21,0 +22,0 @@ "devDependencies": { |
# Raven [![Build Status](https://secure.travis-ci.org/mattrobenolt/raven-node.png?branch=master)](http://travis-ci.org/mattrobenolt/raven-node) | ||
**Node v0.9 compatible** | ||
**Node v0.10 compatible** | ||
@@ -11,3 +11,3 @@ Log errors and stack traces in [Sentry](http://getsentry.com/) from within your Node.js applications. Includes middleware support for [Connect](http://www.senchalabs.org/connect/)/[Express](http://expressjs.com/). | ||
* 0.8.x | ||
* 0.9.x (latest unstable) | ||
* 0.10.x | ||
@@ -27,7 +27,11 @@ ## Installation | ||
Run with: | ||
## Disable Raven | ||
Pass `false` as the DSN (or any falsey value). | ||
```javascript | ||
client = new raven.Client(process.env.NODE_ENV === 'production' && '{{ SENTRY_DSN }}') | ||
``` | ||
$ NODE_ENV=production node script.js | ||
``` | ||
__Note__: We don't infer this from `NODE_ENV` automatically anymore. It's up to you to implement whatever logic you'd like. | ||
## Logging an error | ||
@@ -83,5 +87,2 @@ ```javascript | ||
## Environment variables | ||
### NODE_ENV | ||
`NODE_ENV` must be set to `production` for Sentry to actually work. Without being in production, a warning is issued and logging disabled. | ||
### SENTRY_DSN | ||
@@ -88,0 +89,0 @@ Optionally declare the DSN to use for the client through the environment. Initializing the client in your app won't require setting the DSN. |
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
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
22986
434
164
8
2
+ Addedraw-stacktrace@0.0.2
+ Addedraw-stacktrace@0.0.2(transitive)
+ Addedtraceback@0.3.1(transitive)
+ Addedunderscore@1.13.7(transitive)