Bugsnag Notification Plugin Creation Guide
Bugsnag.com can notify you when errors happen in your applications.
We've created a plugin architecture so you can contribute notification
plugins for services you use.
Bugsnag 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 to start
capturing exceptions from your applications.
Steps to contributing
-
Fork the
bugsnag-notification-plugins project
on GitHub.
-
Create a new folder in /plugins/
for your plugin
-
Create the plugin file as index.js
or index.coffee
, see below for
instructions
-
Create a config.json
file describing the usage and configurable settings
for your plugin
-
Add a 50x50 icon.png
file representing your plugin
-
If necessary, add any node module dependencies to the base package.json
file
-
Make a pull request
from your fork to bugsnag/bugsnag-notification-plugins
Writing your plugin
Notification plugins should be written in JavaScript or CoffeeScript and are
executed in a queue using our internal node.js application.
Plugins should extend the base NotificationPlugin
class defined in
notification-plugin.js
and override the receiveEvent
function to perform
the notification. This method is fired when a new event is triggered.
It is easiest to write plugins using CoffeeScript, for example:
NotificationPlugin = require "../../notification-plugin.js"
class MyPlugin extends NotificationPlugin
@receiveEvent = (config, event) ->
# Do the hard work here
module.exports = MyPlugin
If you prefer to write your plugin with plain old JavaScript, this is also
possible:
var util = require("util");
var NotificationPlugin = require("../../notification-plugin.js")
function MyPlugin() {}
util.inherits(MyPlugin, NotificationPlugin);
MyPlugin.receiveEvent = function (config, event) {
};
module.exports = MyPlugin;
Testing your plugin
By extending the NotificationPlugin
class, you'll be able to test your
plugin directly on the command line. In your new plugin directory
(plugins/your-plugin
) run index.coffee
directly:
> coffee index.coffee --option=value --anotherOption=something
Command line options represent the customizable per-project settings as
defined in your config.json
file.
Note: You should ensure you have run npm install
in the top level
directory first, to install the dependencies for the project.
Event Format
As well as passing the user's plugin configuration settings, we also pass you
an event object, which tells you the reason we triggered a notification.
event: {
account: {
name: "Account Name",
url: "https://bugsnag.com/dashboard/"
},
project: {
name: "Project Name",
url: "https://bugsnag.com/dashboard/project-name"
},
trigger: {
type: "firstException",
message: "New exception"
},
error: {
exceptionClass: "NullPointerException",
message: "Null cannot be dereferenced",
context: "BugsnagMainActivity",
appVersion: "1.2.3",
releaseStage: "production",
occurrences: 1,
firstReceived: new Date(),
usersAffected: 1,
url: "https://bugsnag.com/errors/example",
stacktrace: [{
file: "BugsnagMainActivity.java",
lineNumber: 123,
method: "onCreate",
inProject: true
}
...
]
}
}
HTTP request helper
Since most notification plugins will use http for communication to external
services, we've provided a request
helper function. This function provides
a superagent
request object, which you can
read about here. Some examples:
// Perform a HTTP GET request
@request
.get("http://someurl.com")
.send(params)
.end()
// Perform a normal HTTP POST request
@request
.post("http://someurl.com")
.send(params)
.type("form")
.end()
// Perform a HTTP POST request with a JSON body
@request
.post("http://someurl.com")
.send(params)
.end()
config.json format
Your plugin's config.json
file describes to users how to use and configure
your plugin from their Bugsnag dashboard. The file must be a valid JSON file
and look similar to the following example:
{
"name": "HipChat",
"actions": {
"create": "Post to a HipChat chatroom",
},
"supportedTriggers": ["firstException"],
"type": "communication",
"fields": [{
"name": "authToken",
"label": "Auth Token",
"description": "Your HipChat API auth token",
"type": "boolean",
"allowedValues": ["yellow", "red", "green", "purple", "random"],
"defaultValue": "yellow"
"link": "https://trello.com/1/authorize?key={applicationKey}&name=Bugsnag"
}
...
]
}
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-notification-plugins/issues