Launch Week Day 5: Introducing Reachability for PHP.Learn More
Socket
Book a DemoSign in
Socket

raven

Package Overview
Dependencies
Maintainers
4
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

raven - npm Package Compare versions

Comparing version
1.0.0
to
1.1.0
+168
lib/breadcrumbs.js
'use strict';
var util = require('util');
var utils = require('./utils.js');
/**
* Polyfill a method
* @param obj object e.g. `document`
* @param name method name present on object e.g. `addEventListener`
* @param replacement replacement function
* @param track {optional} record instrumentation to an array
*/
function fill(obj, name, replacement, track) {
var orig = obj[name];
obj[name] = replacement(orig);
if (track) {
track.push([obj, name, orig]);
}
}
var originals = [];
var wrappers = {
console: function (Raven) {
var wrapConsoleMethod = function (level) {
if (!(level in console)) {
return;
}
fill(console, level, function (originalConsoleLevel) {
var sentryLevel = level === 'warn'
? 'warning'
: level;
return function () {
var args = [].slice.call(arguments);
var msg = '' + args.join(' ');
var data = {
level: sentryLevel,
logger: 'console',
extra: {
'arguments': args
}
};
Raven.captureBreadcrumb({
message: msg,
level: data.level,
category: 'console'
});
originalConsoleLevel.apply(console, args);
};
}, originals);
};
['debug', 'info', 'warn', 'error', 'log'].forEach(wrapConsoleMethod);
},
http: function (Raven) {
var http = require('http');
var OrigClientRequest = http.ClientRequest;
var ClientRequest = function (options, cb) {
// Note: this won't capture a breadcrumb if a response never comes
// It would be useful to know if that was the case, though, so
// todo: revisit to see if we can capture sth indicating response never came
// possibility: capture one breadcrumb for "req sent" and one for "res recvd"
// seems excessive but solves the problem and *is* strictly more information
// could be useful for weird response sequencing bug scenarios
var self = this;
OrigClientRequest.call(self, options, cb);
// We could just always grab these from self.agent, self.method, self._headers, self.path, etc
// but certain other http-instrumenting libraries (like nock, which we use for tests) fail to
// maintain the guarantee that after calling OrigClientRequest, those fields will be populated
var url, method;
if (typeof options === 'string') {
url = options;
method = 'GET';
} else {
url = (options.protocol || '') + '//' +
(options.hostname || options.host || '') +
(options.path || '/');
method = options.method || 'GET';
}
// Don't capture breadcrumb for our own requests
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
}
});
// 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 () {});
});
}
};
util.inherits(ClientRequest, OrigClientRequest);
fill(http, 'ClientRequest', function () {
return ClientRequest;
}, originals);
// http.request orig refs module-internal ClientRequest, not exported one, so
// it still points at orig ClientRequest after our monkeypatch; these reimpls
// just get that reference updated to use our new ClientRequest
fill(http, 'request', function () {
return function (options, cb) {
return new http.ClientRequest(options, cb);
};
}, originals);
fill(http, 'get', function () {
return function (options, cb) {
var req = http.request(options, cb);
req.end();
return req;
};
}, originals);
},
postgres: function (Raven) {
// Using fill helper here is hard because of `this` binding
var pg = require('pg');
var origQuery = pg.Connection.prototype.query;
pg.Connection.prototype.query = function (text) {
Raven.captureBreadcrumb({
category: 'postgres',
message: text
});
origQuery.call(this, text);
};
originals.push([pg.Connection.prototype, 'query', origQuery]);
}
};
function instrument(key, Raven) {
try {
wrappers[key](Raven);
utils.consoleAlert('Enabled automatic breadcrumbs for ' + key);
} catch (e) {
// associated module not available
}
}
function restoreOriginals() {
var original;
// eslint-disable-next-line no-cond-assign
while (original = originals.shift()) {
var obj = original[0];
var name = original[1];
var orig = original[2];
obj[name] = orig;
}
}
module.exports = {
instrument: instrument,
restoreOriginals: restoreOriginals
};
+1
-1

@@ -106,3 +106,3 @@ <!doctype html>

Code coverage
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Fri Dec 09 2016 19:27:18 GMT-0800 (PST)
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Tue Dec 13 2016 00:27:23 GMT-0800 (PST)
</div>

@@ -109,0 +109,0 @@ </div>

@@ -80,3 +80,3 @@ <!doctype html>

Code coverage
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Fri Dec 09 2016 19:27:18 GMT-0800 (PST)
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Tue Dec 13 2016 00:27:23 GMT-0800 (PST)
</div>

@@ -83,0 +83,0 @@ </div>

@@ -94,3 +94,3 @@ <!doctype html>

Code coverage
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Fri Dec 09 2016 19:27:18 GMT-0800 (PST)
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Tue Dec 13 2016 00:27:23 GMT-0800 (PST)
</div>

@@ -97,0 +97,0 @@ </div>

@@ -214,8 +214,3 @@ <!doctype html>

168
169
170
171
172
173
174</td><td class="line-coverage quiet"><span class="cline-any cline-neutral">&nbsp;</span>
169</td><td class="line-coverage quiet"><span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>

@@ -308,7 +303,2 @@ <span class="cline-any cline-yes">1×</span>

<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">3×</span>

@@ -481,7 +471,2 @@ <span class="cline-any cline-yes">2×</span>

&nbsp;
// console.log('capturing breadcrumb');
// console.log(Raven.raw_dsn);
// console.log(Raven.dsn);
// console.log(url);
// console.log(url.indexOf(Raven.dsn.public_key));
// Don't capture breadcrumb for our own requests

@@ -574,3 +559,3 @@ if (!Raven.dsn || url.indexOf(Raven.dsn.host) === -1) {

Code coverage
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Fri Dec 09 2016 19:27:18 GMT-0800 (PST)
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Tue Dec 13 2016 00:27:23 GMT-0800 (PST)
</div>

@@ -577,0 +562,0 @@ </div>

@@ -579,3 +579,9 @@ <!doctype html>

533
534</td><td class="line-coverage quiet"><span class="cline-any cline-neutral">&nbsp;</span>
534
535
536
537
538
539
540</td><td class="line-coverage quiet"><span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>

@@ -625,2 +631,6 @@ <span class="cline-any cline-yes">1×</span>

<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">78×</span>

@@ -631,2 +641,3 @@ <span class="cline-any cline-neutral">&nbsp;</span>

<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">78×</span>

@@ -992,2 +1003,3 @@ <span class="cline-any cline-yes">78×</span>

<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-neutral">&nbsp;</span>
<span class="cline-any cline-yes">4×</span>

@@ -1161,2 +1173,6 @@ <span class="cline-any cline-neutral">&nbsp;</span>

&nbsp;
// autoBreadcrumbs: true enables all, autoBreadcrumbs: false disables all
// autoBreadcrumbs: { http: true } enables a single type
// this procedure will ensure that this.autoBreadcrumbs is an object populated
// with keys -&gt; bools reflecting actual status of all breadcrumb types
var autoBreadcrumbDefaults = {

@@ -1167,3 +1183,4 @@ console: false,

};
this.maxBreadcrumbs = Math.max(0, Math.min(options.maxBreadcrumbs || 100, 100));
// default to 30, don't allow higher than 100
this.maxBreadcrumbs = Math.max(0, Math.min(options.maxBreadcrumbs || 30, 100));
this.autoBreadcrumbs = extend({}, autoBreadcrumbDefaults);

@@ -1528,2 +1545,3 @@ if (typeof options.autoBreadcrumbs !== 'undefined') {

captureBreadcrumb: function (breadcrumb) {
// Avoid capturing global-scoped breadcrumbs before instrumentation finishes
<span class="missing-if-branch" title="if path not taken" >I</span>if (!this.installed) <span class="cstat-no" title="statement not covered" >return;</span>

@@ -1658,3 +1676,3 @@ &nbsp;

Code coverage
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Fri Dec 09 2016 19:27:18 GMT-0800 (PST)
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Tue Dec 13 2016 00:27:23 GMT-0800 (PST)
</div>

@@ -1661,0 +1679,0 @@ </div>

@@ -132,3 +132,3 @@ <!doctype html>

Code coverage
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Fri Dec 09 2016 19:27:18 GMT-0800 (PST)
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Tue Dec 13 2016 00:27:23 GMT-0800 (PST)
</div>

@@ -135,0 +135,0 @@ </div>

@@ -124,3 +124,3 @@ <!doctype html>

Code coverage
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Fri Dec 09 2016 19:27:18 GMT-0800 (PST)
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Tue Dec 13 2016 00:27:23 GMT-0800 (PST)
</div>

@@ -127,0 +127,0 @@ </div>

@@ -80,3 +80,3 @@ <!doctype html>

Code coverage
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Fri Dec 09 2016 19:27:18 GMT-0800 (PST)
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Tue Dec 13 2016 00:27:23 GMT-0800 (PST)
</div>

@@ -83,0 +83,0 @@ </div>

@@ -595,3 +595,3 @@ <!doctype html>

Code coverage
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Fri Dec 09 2016 19:27:18 GMT-0800 (PST)
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Tue Dec 13 2016 00:27:23 GMT-0800 (PST)
</div>

@@ -598,0 +598,0 @@ </div>

@@ -286,3 +286,3 @@ <!doctype html>

Code coverage
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Fri Dec 09 2016 19:27:18 GMT-0800 (PST)
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Tue Dec 13 2016 00:27:23 GMT-0800 (PST)
</div>

@@ -289,0 +289,0 @@ </div>

@@ -673,3 +673,3 @@ <!doctype html>

Code coverage
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Fri Dec 09 2016 19:27:18 GMT-0800 (PST)
generated by <a href="http://istanbul-js.org/" target="_blank">istanbul</a> at Tue Dec 13 2016 00:27:23 GMT-0800 (PST)
</div>

@@ -676,0 +676,0 @@ </div>

@@ -0,3 +1,33 @@

# 1.1.0 - 12/12/2016
- Added support for (automatic) breadcrumbs [See #240]
- `Raven.captureBreadcrumb` manual method
- `autoBreadcrumbs` config field to automatically capture breadcrumbs for:
- console logs
- http requests
- postgres queries
- Deprecate `captureQuery` [See #239]
# 1.0.0 - 12/12/2016
- `Raven.config(...)` instead of `new raven.Client(...)`
- `Raven.install()` instead of `client.patchGlobal()`
- The callback to `Raven.captureException` now fires after transmission [See #217]
- Added `captureUnhandledRejections` option for Promise rejections
- Introduced contexts and associated `set/merge/getContext` methods [See #207]
- Added `shouldSendCallback` config option and `set*Callback` methods [See #220]
- Added `intercept()` method [See #225]
- Backwards compatibility was mostly maintained, but lots of stuff was deprecated
- We'll print console messages if you're doing anything the old way
- We'll also print console messages in certain situations where behavior might be surprising, like if no DSN is configured
- You can disable these alerts with `Raven.disableConsoleAlerts();`
# 0.12.3 - 11/21/2016
* Replace `node-uuid` dependency with `uuid` [See #236]
# 0.12.2 - 11/17/2016
* Add column number to stack frames [See #235]
* Check that `require.main.filename` is defined [See #233]
# 0.12.1 - 8/4/2016
* Fix bug where `environment` option was not actually being transmitted to Sentry [See #185]
# 0.12.0 - 8/1/2016

@@ -4,0 +34,0 @@ * Add `environment` config option and `setRelease` method [See #179]

@@ -12,6 +12,11 @@ 'use strict';

var domain = require('domain');
var autoBreadcrumbs = require('./breadcrumbs');
var extend = utils.extend;
function Raven() {}
function Raven() {
this.breadcrumbs = {
record: this.captureBreadcrumb.bind(this)
};
}

@@ -42,2 +47,26 @@ nodeUtil.inherits(Raven, events.EventEmitter);

// autoBreadcrumbs: true enables all, autoBreadcrumbs: false disables all
// autoBreadcrumbs: { http: true } enables a single type
// this procedure will ensure that this.autoBreadcrumbs is an object populated
// with keys -> bools reflecting actual status of all breadcrumb types
var autoBreadcrumbDefaults = {
console: false,
http: false,
pg: false
};
// default to 30, don't allow higher than 100
this.maxBreadcrumbs = Math.max(0, Math.min(options.maxBreadcrumbs || 30, 100));
this.autoBreadcrumbs = extend({}, autoBreadcrumbDefaults);
if (typeof options.autoBreadcrumbs !== 'undefined') {
for (var key in autoBreadcrumbDefaults) {
if (autoBreadcrumbDefaults.hasOwnProperty(key)) {
if (typeof options.autoBreadcrumbs === 'boolean') {
this.autoBreadcrumbs[key] = options.autoBreadcrumbs;
} else if (typeof options.autoBreadcrumbs[key] === 'boolean') {
this.autoBreadcrumbs[key] = options.autoBreadcrumbs[key];
}
}
}
}
this.captureUnhandledRejections = options.captureUnhandledRejections;

@@ -76,2 +105,4 @@ this.loggerName = options.logger || '';

install: function install(opts, cb) {
if (this.installed) return this;
if (typeof opts === 'function') {

@@ -85,5 +116,28 @@ cb = opts;

}
for (var key in this.autoBreadcrumbs) {
if (this.autoBreadcrumbs.hasOwnProperty(key)) {
this.autoBreadcrumbs[key] && autoBreadcrumbs.instrument(key, this);
}
}
this.installed = true;
return this;
},
uninstall: function uninstall() {
if (!this.installed) return this;
autoBreadcrumbs.restoreOriginals();
// todo: this works for tests for now, but isn't what we ultimately want to be doing
process.removeAllListeners('uncaughtException');
process.removeAllListeners('unhandledRejection');
this.installed = false;
return this;
},
generateEventId: function generateEventId() {

@@ -101,2 +155,3 @@ return uuid().replace(/-/g, '');

var domainContext = domain.active && domain.active.sentryContext || {};

@@ -106,2 +161,5 @@ kwargs.user = extend({}, this._globalContext.user, domainContext.user, kwargs.user);

kwargs.extra = extend({}, this._globalContext.extra, domainContext.extra, kwargs.extra);
kwargs.breadcrumbs = {
values: domainContext.breadcrumbs || []
};

@@ -201,16 +259,2 @@ kwargs.modules = utils.getModules();

captureQuery: function captureQuery(query, engine, kwargs, cb) {
if (!cb && typeof kwargs === 'function') {
cb = kwargs;
kwargs = {};
} else {
kwargs = kwargs || {};
}
var eventId = this.generateEventId();
this.process(eventId, parsers.parseQuery(query, engine, kwargs), cb);
return eventId;
},
/* The onErr param here is sort of ugly and won't typically be used

@@ -246,3 +290,3 @@ * but it lets us write the requestHandler middleware in terms of this function.

onErr = function (err) {
self.captureException(err, wrapDomain.sentryContext);
self.captureException(err);
};

@@ -311,3 +355,11 @@ }

getContext: function getContext() {
return domain.active ? domain.active.sentryContext : this._globalContext;
if (domain.active) {
if (!domain.active.sentryContext) {
domain.active.sentryContext = {};
utils.consoleAlert('sentry context not found on active domain');
}
return domain.active.sentryContext;
}
utils.consoleAlert('getContext called without context; this may indicate incorrect setup - refer to docs on contexts');
return this._globalContext;
},

@@ -370,6 +422,23 @@

};
},
captureBreadcrumb: function (breadcrumb) {
// Avoid capturing global-scoped breadcrumbs before instrumentation finishes
if (!this.installed) return;
breadcrumb = extend({
timestamp: +new Date / 1000
}, breadcrumb);
var currCtx = this.getContext();
if (!currCtx.breadcrumbs) currCtx.breadcrumbs = [];
currCtx.breadcrumbs.push(breadcrumb);
if (currCtx.breadcrumbs.length > this.maxBreadcrumbs) {
currCtx.breadcrumbs.shift();
}
this.setContext(currCtx);
}
});
// Deprecations

@@ -382,7 +451,11 @@ extend(Raven.prototype, {

captureError: function captureError() {
utils.consoleAlert('captureError has been deprecated and will be removed in v2.0');
utils.consoleAlert('captureError has been deprecated and will be removed in v2.0; use captureException instead');
return this.captureException.apply(this, arguments);
},
captureQuery: function captureQuery() {
utils.consoleAlert('captureQuery has been deprecated and will be removed in v2.0');
return this;
},
patchGlobal: function (cb) {
utils.consoleAlert('patchGlobal has been deprecated and will be removed in v2.0');
utils.consoleAlert('patchGlobal has been deprecated and will be removed in v2.0; use install instead');
registerExceptionHandler(this, cb);

@@ -389,0 +462,0 @@ return this;

@@ -56,12 +56,2 @@ 'use strict';

module.exports.parseQuery = function parseQuery(query, engine, kwargs) {
kwargs = kwargs || {};
kwargs.message = query;
kwargs.query = {
query: query,
engine: engine
};
return kwargs;
};
module.exports.parseRequest = function parseRequest(req, kwargs) {

@@ -68,0 +58,0 @@ kwargs = kwargs || {};

@@ -12,3 +12,3 @@ {

],
"version": "1.0.0",
"version": "1.1.0",
"repository": "git://github.com/getsentry/raven-node.git",

@@ -24,2 +24,3 @@ "author": "Matt Robenolt <matt@ydekproductions.com>",

"test": "NODE_ENV=test istanbul cover _mocha -- --reporter dot && NODE_ENV=test node_modules/coffee-script/bin/coffee ./test/run.coffee",
"test-full": "npm run test && cd test/instrumentation && ./run.sh",
"lint": "node_modules/eslint/bin/eslint.js ."

@@ -26,0 +27,0 @@ },

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet