Skip to content

Commit

Permalink
Merge pull request #49 from MindscapeHQ/custom-error-group
Browse files Browse the repository at this point in the history
Custom error group
  • Loading branch information
dwnz committed Dec 3, 2015
2 parents b3fbfcb + 677c5ec commit b26ac5f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,28 @@ See [lib/raygun.offline.js](lib/raygun.offline.js) for an example.

We recommend that you limit the number of errors that you are caching so that you don't swamp the clients internet connection sending errors.

### Custom error grouping

You can provide your own grouping key if you wish. We only recommend this you're having issues with errors not being grouped properly.

When initializing Raygun, pass through a `groupingKey` function.

var raygunClient = new raygun.Client().init({
apiKey: 'YOUR_KEY',
groupingKey: function(message, exception, customData, request, tags) {
return "CUSTOMKEY";
}
});

### Examples
View a screencast on creating an app with Node.js and Express.js, then hooking up the error handling and sending them at [http://raygun.io/blog/2013/07/video-nodejs-error-handling-with-raygun/](http://raygun.io/blog/2013/07/video-nodejs-error-handling-with-raygun/)

## Contributing
In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using "npm test".

## Release History

- 0.8.1 - Add custom error grouping key
- 0.8.0 - Add offline support
- 0.7.1 - Default useSSL to true
- 0.7.0 - Add onBeforeSend hook, api endpoint options, and bug fixes
Expand Down
13 changes: 12 additions & 1 deletion lib/raygun.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var MessageBuilder = require('./raygun.messageBuilder');
var OfflineStorage = require('./raygun.offline');

var Raygun = function () {
var _apiKey, _filters, raygun = this, _user, _version, _host, _port, _useSSL, _onBeforeSend, _offlineStorage, _isOffline, _offlineStorageOptions;
var _apiKey, _filters, raygun = this, _user, _version, _host, _port, _useSSL, _onBeforeSend, _offlineStorage, _isOffline, _offlineStorageOptions, _groupingKey;

raygun.init = function (options) {
_apiKey = options.apiKey;
Expand All @@ -27,6 +27,7 @@ var Raygun = function () {
_offlineStorage = options.offlineStorage || new OfflineStorage();
_offlineStorageOptions = options.offlineStorageOptions;
_isOffline = options.isOffline;
_groupingKey = options.groupingKey;

if(_isOffline) {
_offlineStorage.init(_offlineStorageOptions);
Expand Down Expand Up @@ -56,6 +57,11 @@ var Raygun = function () {
return raygun;
};

raygun.groupingKey = function (groupingKey) {
_groupingKey = groupingKey;
return raygun;
};

raygun.offline = function() {
_offlineStorage.init(_offlineStorageOptions);
_isOffline = true;
Expand All @@ -78,6 +84,11 @@ var Raygun = function () {
.setTags(tags);

var message = builder.build();

if (_groupingKey) {
message.details.groupingKey = typeof _groupingKey === 'function' ? _groupingKey(message, exception, customData, request, tags) : null;
}

if (raygun.onBeforeSend) {
message = typeof _onBeforeSend === 'function' ? _onBeforeSend(message, exception, customData, request, tags) : message;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "raygun",
"description": "Raygun.io plugin for Node",
"version": "0.8.0",
"version": "0.8.1",
"homepage": "https://github.com/MindscapeHQ/raygun4node",
"author": {
"name": "MindscapeHQ",
Expand Down

0 comments on commit b26ac5f

Please sign in to comment.