Skip to content

Commit 53c5f9f

Browse files
author
Kevin Cornbower
committed
Added metadata on a per-error basis
1 parent 0709bc9 commit 53c5f9f

File tree

5 files changed

+64
-6
lines changed

5 files changed

+64
-6
lines changed

README.md

+16-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ This extension requires iOS 6.0 or higher and Android 2.2 (API level 8) or highe
1717

1818
## Binary Files
1919

20-
You can find the final compiled ANE binary along with the swc file in the bin folder.
20+
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.
2121

2222

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

106106
```
107-
Bugsnag.notify("Big Error", "A really big error has occured");
107+
Bugsnag.notify("Big Error", "A really big error has occurred");
108108
```
109109

110110
You can also add a severity to it:
111111

112112
```
113-
Bugsnag.notify("Big Error", "A really big error has occured", Severity.INFO);
113+
Bugsnag.notify("Big Error", "A really big error has occurred", Severity.INFO);
114114
```
115115

116-
It may be helpful to provide a stacktrace of where the error occured:
116+
It may be helpful to provide a stacktrace of where the error occurred:
117117

118118
```
119-
Bugsnag.notify("Big Error", "A really big error has occured", Severity.INFO, new Error().getStackTrace());
119+
Bugsnag.notify("Big Error", "A really big error has occurred", Severity.INFO, new Error().getStackTrace());
120+
```
121+
122+
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.
123+
124+
```
125+
var metadata:Metadata = new Metadata("Error Details");
126+
metadata.addAttribute("Description", "Something went really wrong");
127+
128+
Bugsnag.notify("Big Error", "A really big error has occurred", Serverity.INFO, new Error().getStackTrace(), new <Metadata>[metadata]);
120129
```
121130

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

192+
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.
193+
183194
### Context
184195

185196
The context represents the state the application is in before the error. You can set the context:

actionscript/src/com/bugsnag/Bugsnag.as

+20-1
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,9 @@ package com.bugsnag
107107
* @param message
108108
* @param severity
109109
* @param stackTrace
110+
* @param metadata
110111
*/
111-
public static function notify(name:String, message:String, severity:String = "error", stackTrace:String = null):void
112+
public static function notify(name:String, message:String, severity:String = "error", stackTrace:String = null, metadata:Vector.<Metadata> = null):void
112113
{
113114
if(actionscriptKey == null)
114115
{
@@ -125,6 +126,15 @@ package com.bugsnag
125126
obj.apiKey = actionscriptKey;
126127
obj.notifier = {name: "Bugsnag ANE", version: "1.0.0", url: "https://github.com/DigitalStrawberry/ANE-Bugsnag"};
127128

129+
// Merge metadata
130+
if(metadata != null && metadata.length > 0)
131+
{
132+
for each(var data:Metadata in metadata)
133+
{
134+
_tabs[data.name] = data.data;
135+
}
136+
}
137+
128138
// Event
129139
var event:Object = {};
130140
event.payloadVersion = "2";
@@ -173,6 +183,15 @@ package com.bugsnag
173183
request.url = BUGSNAG_URL;
174184
request.data = JSON.stringify(obj);
175185
_requests.request(request);
186+
187+
// Cleanup metadata
188+
if(metadata != null && metadata.length > 0)
189+
{
190+
for each(var data:Metadata in metadata)
191+
{
192+
removeParameterFromObject(_tabs, data.name);
193+
}
194+
}
176195
}
177196

178197

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.bugsnag
2+
{
3+
public class Metadata
4+
{
5+
private var _name:String;
6+
private var _data:Object = {};
7+
8+
public function Metadata(name:String)
9+
{
10+
_name = name;
11+
}
12+
13+
public function addAttribute(name:String, value:String):void
14+
{
15+
_data[name] = value;
16+
}
17+
18+
public function get name():String
19+
{
20+
return _name;
21+
}
22+
23+
public function get data():Object
24+
{
25+
return _data;
26+
}
27+
}
28+
}

bin/ANEBugsnag.ane

2.43 KB
Binary file not shown.

bin/ANEBugsnag.swc

768 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)