UNPKG

9.16 kBMarkdownView Raw
1Bugsnag Notification Plugin Creation Guide
2==========================================
3
4Bugsnag.com can notify you when errors happen in your applications.
5We've created a plugin architecture so you can contribute notification
6plugins for services you use.
7
8[Bugsnag](http://bugsnag.com) captures errors in real-time from your web,
9mobile and desktop applications, helping you to understand and resolve them
10as fast as possible. [Create a free account](http://bugsnag.com) to start
11capturing exceptions from your applications.
12
13
14Steps to contributing
15---------------------
16
17- [Fork](https://help.github.com/articles/fork-a-repo) the
18 [bugsnag-notification-plugins project](https://github.com/bugsnag/bugsnag-notification-plugins)
19 on GitHub.
20
21- Create a new folder in `/plugins/` for your plugin
22
23- Create the plugin file as `index.js` or `index.coffee`, see below for
24 instructions
25
26- Create a `config.json` file describing the usage and configurable settings
27 for your plugin
28
29- Add a 50x50 `icon.png` file representing your plugin
30
31- If necessary, add any node module dependencies to the base `package.json`
32 file
33
34- [Make a pull request](https://help.github.com/articles/using-pull-requests)
35 from your fork to [bugsnag/bugsnag-notification-plugins](https://github.com/bugsnag/bugsnag-notification-plugins)
36
37
38Writing your plugin
39-------------------
40
41Notification plugins should be written in JavaScript or CoffeeScript and are
42executed in a queue using our internal node.js application.
43
44Plugins should extend the base `NotificationPlugin` class defined in
45`notification-plugin.js` and override the `receiveEvent` function to perform
46the notification. This method is fired when a new event is triggered.
47
48It is easiest to write plugins using CoffeeScript, for example:
49
50```coffeescript
51NotificationPlugin = require "../../notification-plugin.js"
52class MyPlugin extends NotificationPlugin
53 @receiveEvent = (config, event) ->
54 # Do the hard work here
55
56module.exports = MyPlugin
57```
58
59If you prefer to write your plugin with plain old JavaScript, this is also
60possible:
61
62```javascript
63var util = require("util");
64var NotificationPlugin = require("../../notification-plugin.js")
65
66function MyPlugin() {}
67util.inherits(MyPlugin, NotificationPlugin);
68MyPlugin.receiveEvent = function (config, event) {
69 // Do the hard work here
70};
71
72module.exports = MyPlugin;
73```
74
75
76Testing your plugin
77-------------------
78
79By extending the `NotificationPlugin` class, you'll be able to test your
80plugin directly on the command line. In your new plugin directory
81(`plugins/your-plugin`) run `index.coffee` directly:
82
83 > coffee index.coffee --option=value --anotherOption=something
84
85Command line options represent the customizable per-project settings as
86defined in your `config.json` file.
87
88> Note: You should ensure you have run `npm install` in the top level
89directory first, to install the dependencies for the project.
90
91
92Event Format
93------------
94As well as passing the user's plugin configuration settings, we also pass you
95an event object, which tells you the reason we triggered a notification.
96
97```javascript
98event: {
99
100 // Contains information about the account which has had an event
101 account: {
102 // The account name
103 name: "Account Name",
104
105 // The url for the Bugsnag dashboard of the account
106 url: "https://bugsnag.com/dashboard/"
107 },
108
109 // Contains information about the project which has had an event
110 project: {
111 // The project name
112 name: "Project Name",
113
114 // The url for the Bugsnag dashboard of the project
115 url: "https://bugsnag.com/dashboard/project-name"
116 },
117
118 // The reason the user is being notified by the notifier
119 trigger: {
120 // The identifier for the reason for notification
121 type: "firstException",
122
123 // The human readable form of the trigger. This can be used to start
124 // a sentence.
125 message: "New exception"
126 },
127
128 // The error that caused the notification (optional). Will not be present if
129 // the project has hit the rate limit.
130 error: {
131 // The class of exception that caused the error
132 exceptionClass: "NullPointerException",
133
134 // The message that came with the exception. This may not be present if
135 // the exception didn't generate one.
136 message: "Null cannot be dereferenced",
137
138 // The context that was active in the application when the error
139 // occurred. This could be which screen
140 // the user was using at the time, for example.
141 context: "BugsnagMainActivity",
142
143 // The application version
144 appVersion: "1.2.3",
145
146 // The release stage, will most often be production, or development.
147 releaseStage: "production",
148
149 // The number of times this exception has occurred (including this one)
150 occurrences: 1,
151
152 // When was the error first received. Will be a Date object.
153 firstReceived: new Date(),
154
155 // How many users have been affected. Could be 0 if there was no user
156 // associated with the error.
157 usersAffected: 1,
158
159 // The URL on bugsnag.com with the full details about this error
160 url: "https://bugsnag.com/errors/example",
161
162 // The stack trace for this error. An array of stack frames.
163 stacktrace: [{
164 // The file that this stack frame was in.
165 file: "BugsnagMainActivity.java",
166
167 // The line number of the stack frame, within the file.
168 lineNumber: 123,
169
170 // The method that was being executed.
171 method: "onCreate",
172
173 // Indicates that this stack fram was within the project. If the key
174 //is not present, it is assumed to be false.
175 inProject: true
176 }
177 ...
178 ]
179 }
180}
181```
182
183HTTP request helper
184-------------------
185
186Since most notification plugins will use http for communication to external
187services, we've provided a `request` helper function. This function provides
188a `superagent` request object, which you can
189[read about here](http://visionmedia.github.com/superagent/). Some examples:
190
191```coffeescript
192// Perform a HTTP GET request
193@request
194 .get("http://someurl.com")
195 .send(params)
196 .end()
197
198
199// Perform a normal HTTP POST request
200@request
201 .post("http://someurl.com")
202 .send(params)
203 .type("form")
204 .end()
205
206
207// Perform a HTTP POST request with a JSON body
208@request
209 .post("http://someurl.com")
210 .send(params)
211 .end()
212```
213
214
215config.json format
216------------------
217
218Your plugin's `config.json` file describes to users how to use and configure
219your plugin from their Bugsnag dashboard. The file must be a valid JSON file
220and look similar to the following example:
221
222```javascript
223{
224 // The name of the plugin.
225 "name": "HipChat",
226
227 // A description of the action that will be performed.
228 "actions": {
229 "create": "Post to a HipChat chatroom",
230 },
231
232 // We trigger notifications when certain events occur in bugsnag (see the
233 // Event Format documentation above). To signal which triggers your plugin
234 // understands, set this to an array of trigger strings.
235 // eg. ["exception", "firstException"].
236 "supportedTriggers": ["firstException"],
237
238 // The type of plugin ("issueTracker", "communication", or "other")
239 "type": "communication",
240
241 // An array of fields to present to the user on the Bugsnag.com dashboard.
242 "fields": [{
243 // The name of the field. This is how you will reference the field in
244 // the configuration options that are passed to your notifier when it is
245 // run. Should be camelCase.
246 "name": "authToken",
247
248 // The label to display to the user for this field
249 "label": "Auth Token",
250
251 // A full description or hint for this field.
252 "description": "Your HipChat API auth token",
253
254 // The data type of this field, either string, select, password or boolean
255 // (optional, defaults to string)
256 "type": "boolean",
257
258 // An array of selectable values to present in the dropdown list
259 // (required when type == "select").
260 "allowedValues": ["yellow", "red", "green", "purple", "random"],
261
262 // A default value for this field (optional).
263 "defaultValue": "yellow"
264
265 // A link to documentation for this field - or a method of obtaining the value (optional)
266 // Can also contain other fields by using {fieldName} in the URL. In the following example
267 // applicationKey is another configuration option that is required for this URL.
268 "link": "https://trello.com/1/authorize?key={applicationKey}&name=Bugsnag"
269 }
270 ...
271 ]
272}
273```
274
275Reporting Bugs or Feature Requests
276----------------------------------
277
278Please report any bugs or feature requests on the github issues page for this
279project here:
280
281<https://github.com/bugsnag/bugsnag-notification-plugins/issues>