Skip to content

Commit

Permalink
Added metadata on a per-error basis
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Cornbower committed Jan 9, 2016
1 parent 0709bc9 commit 53c5f9f
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 6 deletions.
21 changes: 16 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ This extension requires iOS 6.0 or higher and Android 2.2 (API level 8) or highe

## Binary Files

You can find the final compiled ANE binary along with the swc file in the bin folder.
You can find the final compiled ANE binary along with the swc file in the bin folder or on the [releases](https://github.com/DigitalStrawberry/ANE-Bugsnag/releases) page.


## Setup the Extension
Expand Down Expand Up @@ -104,19 +104,28 @@ Bugsnag.notifyError(new Error(), Severity.WARN);
You aren't limited to tracking only ```Error``` objects. You can send a generic error:

```
Bugsnag.notify("Big Error", "A really big error has occured");
Bugsnag.notify("Big Error", "A really big error has occurred");
```

You can also add a severity to it:

```
Bugsnag.notify("Big Error", "A really big error has occured", Severity.INFO);
Bugsnag.notify("Big Error", "A really big error has occurred", Severity.INFO);
```

It may be helpful to provide a stacktrace of where the error occured:
It may be helpful to provide a stacktrace of where the error occurred:

```
Bugsnag.notify("Big Error", "A really big error has occured", Severity.INFO, new Error().getStackTrace());
Bugsnag.notify("Big Error", "A really big error has occurred", Severity.INFO, new Error().getStackTrace());
```

You can also provide additional metadata for errors that will show up in a custom tab on the Bugsnag dashboard. Each metadata object will display as a new tab.

```
var metadata:Metadata = new Metadata("Error Details");
metadata.addAttribute("Description", "Something went really wrong");
Bugsnag.notify("Big Error", "A really big error has occurred", Serverity.INFO, new Error().getStackTrace(), new <Metadata>[metadata]);
```

## Additional Settings
Expand Down Expand Up @@ -180,6 +189,8 @@ Or even remove entire custom tabs:
Bugsnag.removeTab("My Tab");
```

Note that custom tabs will show up for every error that you log, including native errors. You should use the ```metadata``` parameter of the ```notify``` method if you only want to include custom data for a single event.

### Context

The context represents the state the application is in before the error. You can set the context:
Expand Down
21 changes: 20 additions & 1 deletion actionscript/src/com/bugsnag/Bugsnag.as
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ package com.bugsnag
* @param message
* @param severity
* @param stackTrace
* @param metadata
*/
public static function notify(name:String, message:String, severity:String = "error", stackTrace:String = null):void
public static function notify(name:String, message:String, severity:String = "error", stackTrace:String = null, metadata:Vector.<Metadata> = null):void
{
if(actionscriptKey == null)
{
Expand All @@ -125,6 +126,15 @@ package com.bugsnag
obj.apiKey = actionscriptKey;
obj.notifier = {name: "Bugsnag ANE", version: "1.0.0", url: "https://github.com/DigitalStrawberry/ANE-Bugsnag"};

// Merge metadata
if(metadata != null && metadata.length > 0)
{
for each(var data:Metadata in metadata)
{
_tabs[data.name] = data.data;
}
}

// Event
var event:Object = {};
event.payloadVersion = "2";
Expand Down Expand Up @@ -173,6 +183,15 @@ package com.bugsnag
request.url = BUGSNAG_URL;
request.data = JSON.stringify(obj);
_requests.request(request);

// Cleanup metadata
if(metadata != null && metadata.length > 0)
{
for each(var data:Metadata in metadata)
{
removeParameterFromObject(_tabs, data.name);
}
}
}


Expand Down
28 changes: 28 additions & 0 deletions actionscript/src/com/bugsnag/Metadata.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.bugsnag
{
public class Metadata
{
private var _name:String;
private var _data:Object = {};

public function Metadata(name:String)
{
_name = name;
}

public function addAttribute(name:String, value:String):void
{
_data[name] = value;
}

public function get name():String
{
return _name;
}

public function get data():Object
{
return _data;
}
}
}
Binary file modified bin/ANEBugsnag.ane
Binary file not shown.
Binary file modified bin/ANEBugsnag.swc
Binary file not shown.

0 comments on commit 53c5f9f

Please sign in to comment.