Skip to content

Commit

Permalink
Merge pull request #26 from MindscapeHQ/add-tags
Browse files Browse the repository at this point in the history
Add tags
  • Loading branch information
fundead committed Jan 21, 2014
2 parents 33353f4 + 13a41bb commit c32d9be
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 19 deletions.
33 changes: 31 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,46 @@ Raygun.init('yourApiKey', { allowInsecureSubmissions: true });

### Sending custom data

Custom data variables can be placed in an array passed in as the third parameter in the init() call. For instance:
**On initialization:**

Custom data variables (objects, arrays etc) can be added by calling the withCustomData function on the Raygun object:

```javascript
Raygun.init('{{your_api_key}}').attach().withCustomData({ foo: 'bar' });
```

They can also be passed in as the third parameter in the init() call, for instance:

```javascript
Raygun.init('{{your_api_key}}', null, ['the user name']).attach();
Raygun.init('{{your_api_key}}', null, { enviroment: 'production' }).attach();
```

**During a Send:**

You can also pass custom data with manual send calls, with the second parameter. This lets you add variables that are in scope or global when handled in catch blocks. For example:

```javascript
Raygun.send(err, [{customName: 'customData'}];
```
### Adding tags
The Raygun dashboard can also display tags for errors. These are arrays of strings or Numbers. This is done similar to the above custom data, like so:
**On initialization:**
```javascript
Raygun.init('{{your_api_key}}').attach().withTags(['tag1', 'tag2']);
```
**During a Send:**
Pass tags in as the third parameter:
```javascript
Raygun.send(err, null, ['tag']];
```
### Unique user tracking
You can provide the user name or email address of the currently logged in user to Raygun by calling:
Expand All @@ -104,6 +132,7 @@ This will allow you to filter the errors in the dashboard by that version. You c
## Release History
- 1.5.3 - Added support for attaching Tags
- 1.5.2 - Added Bower package; minor bugfix for Ajax functionality
- 1.5.1 - Capture data submitted by jQuery AJAX calls
- 1.5.0 - Allow IE8 to submit errors over HTTP, updated TraceKit to the latest revision
Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "raygun4js",
"version": "1.5.2",
"version": "1.6.0",
"homepage": "http://raygun.io",
"authors": [
"Mindscape <[email protected]>"
Expand Down
29 changes: 22 additions & 7 deletions dist/raygun.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*! Raygun4js - v1.5.2 - 2014-01-09
/*! Raygun4js - v1.6.0 - 2014-01-21
* https://github.com/MindscapeHQ/raygun4js
* Copyright (c) 2014 MindscapeHQ; Licensed MIT */
(function(window, undefined) {
Expand Down Expand Up @@ -1181,6 +1181,7 @@ window.TraceKit = TraceKit;
_debugMode = false,
_allowInsecureSubmissions = false,
_customData = {},
_tags = [],
_user,
_version,
$document;
Expand Down Expand Up @@ -1218,6 +1219,10 @@ window.TraceKit = TraceKit;
return Raygun;
},

withTags: function (tags) {
_tags = tags;
},

attach: function () {
if (!isApiKeyConfigured()) {
return;
Expand All @@ -1237,9 +1242,12 @@ window.TraceKit = TraceKit;
return Raygun;
},

send: function (ex, customData) {
send: function (ex, customData, tags) {
try {
processUnhandledException(_traceKit.computeStackTrace(ex), merge(_customData, customData));
processUnhandledException(_traceKit.computeStackTrace(ex), {
customData: merge(_customData, customData),
tags: mergeArray(_tags, tags)
});
}
catch (traceKitException) {
if (ex !== traceKitException) {
Expand Down Expand Up @@ -1293,6 +1301,12 @@ window.TraceKit = TraceKit;
return o3;
}

function mergeArray(t0, t1) {
if (t1 != null) {
return t0.concat(t1);
}
}

function forEach(set, func) {
for (var i = 0; i < set.length; i++) {
func.call(null, i, set[i]);
Expand Down Expand Up @@ -1340,8 +1354,8 @@ window.TraceKit = TraceKit;
});
}

if (isEmpty(options)) {
options = _customData;
if (isEmpty(options.customData)) {
options.customData = _customData;
}

var screen = window.screen || { width: getViewPort().width, height: getViewPort().height, colorDepth: 8 };
Expand Down Expand Up @@ -1370,9 +1384,10 @@ window.TraceKit = TraceKit;
},
'Client': {
'Name': 'raygun-js',
'Version': '1.5.2'
'Version': '1.6.0'
},
'UserCustomData': options,
'UserCustomData': options.customData,
'Tags': options.tags,
'Request': {
'Url': document.location.href,
'QueryString': qs,
Expand Down
4 changes: 2 additions & 2 deletions dist/raygun.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "raygun",
"title": "Raygun4js",
"description": "Raygun.io plugin for JavaScript",
"version": "1.5.2",
"version": "1.6.0",
"homepage": "https://github.com/MindscapeHQ/raygun4js",
"author": {
"name": "MindscapeHQ",
Expand Down
27 changes: 21 additions & 6 deletions src/raygun.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
_debugMode = false,
_allowInsecureSubmissions = false,
_customData = {},
_tags = [],
_user,
_version,
$document;
Expand Down Expand Up @@ -51,6 +52,10 @@
return Raygun;
},

withTags: function (tags) {
_tags = tags;
},

attach: function () {
if (!isApiKeyConfigured()) {
return;
Expand All @@ -70,9 +75,12 @@
return Raygun;
},

send: function (ex, customData) {
send: function (ex, customData, tags) {
try {
processUnhandledException(_traceKit.computeStackTrace(ex), merge(_customData, customData));
processUnhandledException(_traceKit.computeStackTrace(ex), {
customData: merge(_customData, customData),
tags: mergeArray(_tags, tags)
});
}
catch (traceKitException) {
if (ex !== traceKitException) {
Expand Down Expand Up @@ -126,6 +134,12 @@
return o3;
}

function mergeArray(t0, t1) {
if (t1 != null) {
return t0.concat(t1);
}
}

function forEach(set, func) {
for (var i = 0; i < set.length; i++) {
func.call(null, i, set[i]);
Expand Down Expand Up @@ -173,8 +187,8 @@
});
}

if (isEmpty(options)) {
options = _customData;
if (isEmpty(options.customData)) {
options.customData = _customData;
}

var screen = window.screen || { width: getViewPort().width, height: getViewPort().height, colorDepth: 8 };
Expand Down Expand Up @@ -203,9 +217,10 @@
},
'Client': {
'Name': 'raygun-js',
'Version': '1.5.2'
'Version': '1.6.0'
},
'UserCustomData': options,
'UserCustomData': options.customData,
'Tags': options.tags,
'Request': {
'Url': document.location.href,
'QueryString': qs,
Expand Down

0 comments on commit c32d9be

Please sign in to comment.