Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bugsnag

Package Overview
Dependencies
Maintainers
4
Versions
63
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bugsnag - npm Package Compare versions

Comparing version 1.7.0 to 1.8.0

23

CHANGELOG.md
Changelog
=========
## 1.8.0 (2016-08-26)
### Enhancements
* Add option to set custom headers
[#83](https://github.com/bugsnag/bugsnag-node/pull/83)
* Use `error.name` instead of `error.constructor.name` where available
[Jyrki Laurila](https://github.com/jylauril)
[#77](https://github.com/bugsnag/bugsnag-node/pull/77)
* Invoke notify callback with errors
[Jacob Marshall](https://github.com/jacobmarshall)
[#80](https://github.com/bugsnag/bugsnag-node/pull/80)
### Bug Fixes
* Fix setting default project root when `require.main.filename` does not exist
* Clone objects before filtering to avoid modifying referenced objects
[Percy Hatcherson](https://github.com/primitive-type)
[#82](https://github.com/bugsnag/bugsnag-node/pull/82)
* Remove duplicated scrubbed metadata from request payloads
[#72](https://github.com/bugsnag/bugsnag-node/pull/72)
## 1.7.0 (2016-01-27)

@@ -5,0 +28,0 @@

4

CONTRIBUTING.md

@@ -65,1 +65,5 @@ Contributing

### Update docs.bugsnag.com
Update the setup guides for JavaScript and CoffeeScript with Node with any new
content.

@@ -94,3 +94,7 @@ var domain = require("domain"),

if (cb) {
cb();
if (!Configuration.apiKey) {
cb(new Error("Bugsnag has not been configured with an api key!"));
} else {
cb(new Error("Current release stage not permitted to send events to Bugsnag."));
}
}

@@ -97,0 +101,0 @@ return;

4

lib/configuration.js

@@ -11,6 +11,7 @@ var path = require("path"),

notifyReleaseStages: null,
projectRoot: require.main === undefined ? null : path.dirname(require.main.filename),
projectRoot: require.main !== undefined && require.main.filename !== undefined ? path.dirname(require.main.filename) : null,
autoNotifyUncaught: true,
useSSL: true,
proxy: null,
headers: {},
notifyHost: "notify.bugsnag.com",

@@ -64,2 +65,3 @@ notifyPath: "/",

Configuration.proxy = options.proxy;
Configuration.headers = options.headers;
if (options.projectRoot != null) {

@@ -66,0 +68,0 @@ Configuration.projectRoot = Utils.fullPath(options.projectRoot);

@@ -62,3 +62,3 @@ var stacktrace = require("stack-trace"),

this.message = error.message;
this.errorClass = errorClass || error.constructor.name || error.name || "Error";
this.errorClass = errorClass || error.name || error.constructor.name || "Error";
} else {

@@ -65,0 +65,0 @@ this.message = "[unknown]";

@@ -84,4 +84,4 @@

this.processRequest(event, domainOptions.cleanedRequest);
delete domainOptions.cleanedRequest;
}
delete domainOptions.cleanedRequest;

@@ -124,2 +124,5 @@ if (options.apiKey) {

if (!shouldNotify) {
if (cb) {
cb(new Error("At least one beforeNotify callback prevented the event from being sent to Bugsnag."));
}
return;

@@ -138,3 +141,3 @@ }

// Filter before sending
Utils.filterObject(this.events[0].metaData, Configuration.filters);
this.events[0].metaData = Utils.filterObject(this.events[0].metaData, Configuration.filters);

@@ -158,2 +161,6 @@ var port = Configuration.notifyPort || (Configuration.useSSL ? 443 : 80);

var headers = Utils.cloneObject(Configuration.headers || {});
headers["Content-Type"] = "application/json";
headers["Content-Length"] = Buffer.byteLength(payload, "utf8")
var options = {

@@ -163,6 +170,3 @@ url: "" + (Configuration.useSSL ? "https" : "http") + "://" + Configuration.notifyHost + ":" + port + Configuration.notifyPath,

body: payload,
headers: {
"Content-Type": 'application/json',
"Content-Length": Buffer.byteLength(payload, 'utf8')
}
headers: headers
};

@@ -219,2 +223,1 @@

module.exports = Notification;

@@ -106,2 +106,3 @@ var path = require("path");

}
object = this.cloneObject(object);
var alreadyFiltered = options.alreadyFiltered || [];

@@ -115,3 +116,3 @@ Object.keys(object).forEach(function (key) {

alreadyFiltered.push(object[key]);
Utils.filterObject(object[key], filters, {
object[key] = Utils.filterObject(object[key], filters, {
alreadyFiltered: alreadyFiltered

@@ -123,2 +124,3 @@ });

});
return object;
}

@@ -125,0 +127,0 @@ };

{
"name": "bugsnag",
"description": "Bugsnag notifier for node.js scripts",
"version": "1.7.0",
"version": "1.8.0",
"main": "./lib/bugsnag.js",

@@ -6,0 +6,0 @@ "homepage": "http://bugsnag.com",

@@ -1,441 +0,45 @@

Bugsnag Notifier for Node.js
============================
# Bugsnag error reporter for Node.js
[![Build Status](https://travis-ci.org/bugsnag/bugsnag-node.svg)](https://travis-ci.org/bugsnag/bugsnag-node)
The Bugsnag Notifier for Node.js automatically notifies you of synchronous and asynchronous errors in your Node.js applications.
Automatically detect synchronous and asynchronous errors in your Node.js apps,
collect diagnostic information, and receive notifications immediately.
[Bugsnag](http://bugsnag.com) captures errors in real-time from your web, mobile and desktop applications, helping you to understand and resolve them as fast as possible. [Create a free account](http://bugsnag.com) to start capturing errors from your applications.
## Features
* Automatically report synchronous and asynchronous errors
* Report handled errors
* Attach user information to determine how many people are affected by a crash
* Send customized diagnostic data
Installation & Setup
--------------------
## Getting started
Install bugsnag using npm:
1. [Create a Bugsnag account](https://bugsnag.com)
2. Complete the instructions in the integration guide for your framework:
* [Express or Connect](http://docs.bugsnag.com/platforms/nodejs/express)
* [Koa](http://docs.bugsnag.com/platforms/nodejs/koa)
* [Restify](http://docs.bugsnag.com/platforms/nodejs/restify)
* [Other Node.js apps](http://docs.bugsnag.com/platforms/nodejs/other)
3. Relax!
```bash
npm install bugsnag --save
```
## Support
Require bugsnag in your node.js app:
* Read the configuration reference:
* [Express or Connect](http://docs.bugsnag.com/platforms/nodejs/express/configuration-options)
* [Koa](http://docs.bugsnag.com/platforms/nodejs/koa/configuration-options)
* [Restify](http://docs.bugsnag.com/platforms/nodejs/restify/configuration-options)
* [Other Node.js apps](http://docs.bugsnag.com/platforms/nodejs/other/configuration-options)
* [Search open and closed issues](https://github.com/bugsnag/bugsnag-node/issues?utf8=✓&q=is%3Aissue) for similar problems
* [Report a bug or request a feature](https://github.com/bugsnag/bugsnag-node/issues/new)
```javascript
var bugsnag = require("bugsnag");
```
## Contributing
Register the bugsnag notifier with your API key:
All contributors are welcome! For information on how to build, test
and release `bugsnag-node`, see our
[contributing guide](https://github.com/bugsnag/bugsnag-node/blob/master/CONTRIBUTING.md).
```javascript
bugsnag.register("your-api-key-here");
```
## License
See below for [additional configuration options](#configuration).
Using Express or Connect Middleware
-----------------------------------
If your app uses [Express](http://expressjs.com/) or [Connect](http://www.senchalabs.org/connect/), Bugsnag can automatically capture errors that happen during requests, including errors that happen in asynchronous code.
To ensure that asynchronous errors are routed to the error handler, add the `requestHandler` middleware to your app as the **first middleware**:
```javascript
app.use(bugsnag.requestHandler);
```
You'll also need to add Bugsnag's error handling middleware, make sure to add this after all other middleware, but before any "error" middleware:
```javascript
app.use(bugsnag.errorHandler);
```
Using Restify
-------------
If your app uses [Restify](http://mcavage.me/node-restify/), Bugsnag can automatically capture errors that happen during requests.
To get notified of the errors in your app, just add the Bugsnag restify handler to your code.
```javascript
server.on("uncaughtException", bugsnag.restifyHandler);
```
If you don't use any other uncaughtException event listeners, you will need to add the default handler
back in, like this.
```javascript
server.on("uncaughtException", function (req, res, route, e) {
if (!res._headerSent) res.send(new restify.InternalError(e, e.message || 'unexpected error'));
});
```
Using Koa
----------
If your app uses [Koa](http://koajs.com/), Bugsnag can automatically capture errors that happen during requests.
To get notified of the errors in your app, just add the Bugsnag koa handler to your code.
```javascript
app.on("error", bugsnag.koaHandler)
```
Using Coffeescript
------------------
When executing coffeecript code directly using the `coffee` executable, Bugsnag cannot notify about uncaught exceptions that occur at the top level of your app. This is due to a ["feature"](https://github.com/jashkenas/coffee-script/issues/1438) of the `coffee` executable.
To avoid this issue, make sure to compile your coffeescript files into javascript before running your app.
Using Promises
--------------
If you're using a promises library such as Bluebird or when.js, you can listen to unhandled promise rejections.
See [this document](https://gist.github.com/benjamingr/0237932cee84712951a2) for more details.
```javascript
process.on('unhandledRejection', function (err, promise) {
console.error("Unhandled rejection: " + (err && err.stack || err));
bugsnag.notify(err);
});
```
Send Non-Fatal Exceptions to Bugsnag
------------------------------------
To send non-fatal exceptions to Bugsnag, you can pass any `Error` object or string to the `notify` method:
```javascript
bugsnag.notify(new Error("Non-fatal"));
```
You can also send additional meta data with your exception:
```javascript
bugsnag.notify(new Error("Non-fatal"), {
user: {
username: "bob-hoskins",
name: "Bob Hoskins",
email: "bob@example.com"
}
});
```
### Severity
You can set the severity of an error in Bugsnag by including the severity option when
notifying bugsnag of the error,
```javascript
bugsnag.notify(new Error("Non-fatal"), {
severity: "error"
})
```
Valid severities are `error`, `warning` and `info`.
Severity is displayed in the dashboard and can be used to filter the error list.
By default all crashes (or unhandled exceptions) are set to `error` and all
`bugsnag.notify` calls default to `warning`.
See the full documentation for the [notify](#notify) function for more details.
Capturing Asynchronous Errors
-----------------------------
Bugsnag can automatically capture both synchronous and asynchronous errors in your code if you wrap it in an `autoNotify` function. *Note: If you are using the `bugsnag.requestHandler` middleware for Express or Connect, we automatically wrap your requests with `autoNotify`.*
```javascript
bugsnag.autoNotify(function() {
// Your code here
});
```
Additionally, you can pass options into `autoNotify` that will be used as default options for the notify call to any errors. See the [notify](#notify) docs for more details.
```javascript
bugsnag.autoNotify({ context: "thisContext" }, function() {
// Your code here
});
```
The `autoNotify` function creates a Node.js [`Domain`](http://nodejs.org/api/domain.html) which automatically routes all uncaught errors to Bugsnag.
Capturing Errors in Callback Functions
--------------------------------------
Many callback functions in Node are called with an error as the first argument. Bugsnag can intercept these errors if you wrap your callback with `bugsnag.intercept`:
```javascript
functionWithCallback(bugsnag.intercept(function(argument) {
// Your code here
}));
```
If the first argument is non-null, Bugsnag will be automatically notified of the error, and your callback will not be executed. The first argument is never passed to your callback, since it is assumed to be the error argument.
Configuration
-------------
The `bugsnag.register` can accept an options object as its second parameter. The options can be a combination of any of the following:
### releaseStage
By default, Bugsnag looks at the NODE_ENV environment variable to see what releaseStage the script is running in. If that is not set, Bugsnag assumes you are running in production. If you want to override this behavior, you can set the `releaseStage` option:
```javascript
bugsnag.register("your-api-key-here", { releaseStage: "development" });
```
### notifyReleaseStages
By default the notifier will notify Bugsnag of production and development exceptions. If you wish to be notified about production exceptions only, you can set the `notifyReleaseStages` option.
```javascript
bugsnag.register("your-api-key-here", { notifyReleaseStages: ["production"] });
```
### appVersion
If you use an appVersion to identify releases of your app you can send it to Bugsnag. When set errors will only unresolve when they re-occur in a newer appVersion.
```javascript
bugsnag.register("your-api-key-here", { appVersion: "1.0.0" });
```
### autoNotify
Bugsnag will automatically register for the `uncaughtexception` event. If you do not wish for this to happen, you can disable the functionality as part of the register call:
```javascript
bugsnag.register("your-api-key-here", { autoNotify: false });
```
<!-- Custom anchor for linking from alerts -->
<div id="set-project-root"></div>
### projectRoot
Bugsnag can highlight stacktrace lines that are in your project, and automatically hides stacktrace lines from external libraries. If Bugsnag is not hiding external stacktrace lines, it is likely that the `projectRoot` is being incorrectly calculated. You can set `projectRoot` as part of the register call:
```javascript
bugsnag.register("your-api-key-here", { projectRoot: "/path/to/root" });
```
### packageJSON
If the Bugsnag notifier is unable to locate your `package.json`, you can specify where to find it using `packageJSON`:
```javascript
bugsnag.register("your-api-key-here", { packageJSON: "/path/to/package.json" });
```
### useSSL
By default, errors will be sent to Bugsnag using SSL. To disable SSL, you can set `useSSL`:
```javascript
bugsnag.register("your-api-key-here", { useSSL: false });
```
### onUncaughtError
By default, bugsnag will exit your application if there is an uncaught exception or an uncaught event emitter "error" event. This is in line with standard node.js behaviour. If you want to have different behaviour, then please set onUncaughtError as follows,
```javascript
bugsnag.register("your-api-key-here", { onUncaughtError: function(err){
console.error(err.stack || err);
}});
```
This function is called for all errors that aren't manually sent to bugsnag.notify. So a bugsnag.intercept call will trigger a call to onUncaughtError.
### metaData
It is often very useful to send some extra application or user specific data along with every exception. To do this, you can set the `metaData`:
```javascript
bugsnag.register("your-api-key-here", { metaData: {
user: {
username: "bob-hoskins",
name: "Bob Hoskins",
email: "bob@example.com"
}
}});
```
You can adjust this after calling register by using the `bugsnag.metaData` property.
### proxy
You can use a proxy server by configuring a proxy url when registering with bugsnag.
```javascript
bugsnag.register("your-api-key-here", { proxy: "http://localhost:8080" });
```
### filters
You can prevent some meta-data keys (such as passwords) from being sent to Bugsnag by listing
them in the filters. This is most useful if you're sending request data and don't want to
accidentally log a user's password. The keys are matched with substring matching, so the default
value of `["password"]` also excludes things like `"password_confirmation"`.
```javascript
bugsnag.register("your-api-key-here", { filters: ["password", "creditcard"] }
```
### hostname
By default we'll fetch the hostname using Node's [os.hostname()](https://nodejs.org/api/os.html#os_os_hostname), but you can override this as follows:
```javascript
bugsnag.register("your-api-key-here", { hostname: "web1.example.com" }
```
### onBeforeNotify
If you want to modify error reports just before they are sent to Bugsnag, or prevent them from being sent,
you can add before notify callbacks:
```javascript
Bugsnag.onBeforeNotify(function (notification) {
var metaData = notification.events[0].metaData;
// modify meta-data
metaData.app = {version: '0.3'}
// Don't log error reports from admins
if (metaData.user.is_admin) {
return false;
}
});
```
You can add multiple beforeNotify callbacks, they'll be called in the order you add them.
### sendCode
If you want to send code snippets for each frame of the stacktrace you can enable `sendCode`. This asynchronously loads
any file from the stacktrace, which is within the scope of the project, and sends 3 lines either side of the erroneous line
of code to Bugsnag.
This works almost the same as how Bugsnag JavaScript projects handle sourcemaps - however loading the code is done on the
local machine and sent over the internet with the error data.
```javascript
bugsnag.register("your-api-key-here", { sendCode: true });
```
Notify
------
The `bugsnag.notify` function accepts an error as either a string or an Error object as the first argument, as well as options object as its second parameter. The options can be a combination of any of the following:
### errorName
Errors in your Bugsnag dashboard are grouped by their "error class", to override the error class you can set `errorName`:
```javascript
bugsnag.notify(new Error("Something went badly wrong"), { errorName: "BadError" });
```
### context
A string representing what was happening in your application at the time of the error. In Express/Connect apps, this will automatically be set to the URL of the current request.
```javascript
bugsnag.notify(new Error("Something went badly wrong"), { context: "/users/new" });
```
### userId
A unique identifier for a user affected by this error. This could be any distinct identifier that makes sense for your application. In Express/Connect apps, this is automatically set to the ip address of the current request.
```javascript
bugsnag.notify(new Error("Something went badly wrong"), { userId: "bob-hoskins" });
```
### groupingHash
If you need programmatical control over how the errors are grouped within bugsnag, you can send a groupingHash to the notify call. This will ensure that bugsnag groups all errors with the same groupingHash together.
```javascript
bugsnag.notify(error, { groupingHash: "auth/create" });
```
### metaData
Any extra data you want along with the exception report to Bugsnag. To do this just set other properties on the object, and you will see them as tabs in the error dashboard.
```javascript
bugsnag.notify(new Error("Something went badly wrong"), {
user: {
username: "bob-hoskins",
name: "Bob Hoskins",
email: "bob@example.com"
}
});
```
### severity
You can set the severity of an error in Bugsnag by including the severity option when
notifying bugsnag of the error,
```ruby
bugsnag.notify(new Error("Non-fatal"), {
severity: "error"
})
```
Valid severities are `error`, `warning` and `info`.
Severity is displayed in the dashboard and can be used to filter the error list.
By default all crashes (or unhandled exceptions) are set to `error` and all
`Bugsnag.notify` calls default to `warning`.
### callback
A callback to call after notifying Bugsnag of an error. The callback has two arguments, `err` and `response`. The `err` argument will contain any error received when trying to send the notification, the `response` object will contain the response received from Bugsnag:
```javascript
bugsnag.notify(new Error("Something went badly wrong"), function (error, response) {
if(error) {
// Something went wrong
} else {
// The notify worked
}
})
```
Per-request metaData
--------------------
If you are using our express middleware, or otherwise using domains, you can set per-request metaData.
This metaData will be sent with any crashes occurring during the current request.
```javascript
bugsnag.requestData.user = {id: 5}
```
Reporting Bugs or Feature Requests
----------------------------------
Please report any bugs or feature requests on the github issues page for this project here:
<https://github.com/bugsnag/bugsnag-node/issues>
Contributing
------------
We love pull requests and issues. See [CONTRIBUTING.md](https://github.com/bugsnag/bugsnag-node/blob/master/CONTRIBUTING.md) for instructions :).
License
-------
The Bugsnag Node.js notifier is free software released under the MIT License. See [LICENSE.txt](https://github.com/bugsnag/bugsnag-node/blob/master/LICENSE.txt) for details.
The Bugsnag error reporter for Node.js is free software released under the MIT
License. See
[LICENSE.txt](https://github.com/bugsnag/bugsnag-node/blob/master/LICENSE.txt)
for details.

@@ -1,2 +0,1 @@

// Generated by CoffeeScript 1.8.0
var path = require("path"),

@@ -8,2 +7,3 @@ should = require("chai").should(),

Notification = require("../lib/notification"),
request = require("request"),
apiKey = null,

@@ -19,6 +19,36 @@ deliverStub = null;

beforeEach(function() {
Bugsnag.configure({
notifyReleaseStages: ["production", "development"]
describe("Notification transport", function() {
beforeEach(function() {
sinon.stub(request, "post");
});
afterEach(function() {
request.post.restore();
});
it("sets the application type as JSON", function() {
Bugsnag.configure({
notifyReleaseStages: ["production", "development"]
});
Bugsnag.notify("This is the message");
request.post.firstCall.args[0].headers["Content-Type"].should.equal("application/json");
});
it("adds the configuration headers", function() {
Bugsnag.configure({
notifyReleaseStages: ["production", "development"],
headers: { "Proxy-Authorization" : "Basic dXNlcjuwYXWq" }
});
Bugsnag.notify("This is the message");
request.post.firstCall.args[0].headers["Proxy-Authorization"].should.equal("Basic dXNlcjuwYXWq");
});
it("disallows overwriting the required headers", function() {
Bugsnag.configure({
notifyReleaseStages: ["production", "development"],
headers: { "Content-Type" : "application/x-mp4" }
});
Bugsnag.notify("This is the message");
request.post.firstCall.args[0].headers["Content-Type"].should.equal("application/json");
});
});

@@ -28,2 +58,5 @@

beforeEach(function() {
Bugsnag.configure({
notifyReleaseStages: ["production", "development"]
});
deliverStub = sinon.stub(Notification.prototype, "_deliver");

@@ -30,0 +63,0 @@ });

@@ -232,3 +232,3 @@ // Generated by CoffeeScript 1.8.0

};
Utils.filterObject(testObject, ["firstKey"]);
testObject = Utils.filterObject(testObject, ["firstKey"]);
testObject.should.have.keys(["firstKey", "secondKey"]);

@@ -253,3 +253,3 @@ testObject.should.have.property("firstKey", "[FILTERED]");

};
Utils.filterObject(testObject, ["firstKey", "thirdKey", "thirdObject"]);
testObject = Utils.filterObject(testObject, ["firstKey", "thirdKey", "thirdObject"]);
testObject.should.have.keys(["firstKey", "firstObject"]);

@@ -297,3 +297,3 @@ testObject.should.have.property("firstKey", "[FILTERED]");

data.password = '$secret';
Utils.filterObject(data, ['password']);
data = Utils.filterObject(data, ['password']);

@@ -300,0 +300,0 @@ data.foo.should.equal('bar')

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc