Skip to content

Commit 7f7c066

Browse files
authored
Release v.0.1.0 (#1)
Version 0.1.0. IL2CPP and Mono support for BacktraceClient. BacktraceDatabase isn't supported yet for IL2CPP builds.
1 parent 7ac9ced commit 7f7c066

File tree

537 files changed

+61712
-25215
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

537 files changed

+61712
-25215
lines changed

Backtrace.sln

Lines changed: 0 additions & 37 deletions
This file was deleted.

README.md

Lines changed: 260 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,260 @@
1-
# Backtrace Unity support
1+
# Backtrace Unity support
2+
3+
[Backtrace](http://backtrace.io/)'s integration with unity games allows customers to capture and report handled and unhandled untiy exceptions to their Backtrace instance, instantly offering the ability to prioritize and debug software errors.
4+
5+
[Github Release]:(https://github.com/backtrace-labs/backtrace-labs/)
6+
7+
## Usage
8+
9+
```csharp
10+
11+
//Read from manager BacktraceClient instance
12+
var backtraceClient = GameObject.Find("manager name").GetComponent<BacktraceClient>();
13+
try{
14+
//throw exception here
15+
}
16+
catch(Exception exception){
17+
var report = new BacktraceReport(exception);
18+
backtraceClient.Send(report);
19+
}
20+
```
21+
22+
# Features Summary <a name="features-summary"></a>
23+
* Light-weight Unity client that quickly submits crashed generated in Unity environment to your Backtrace dashboard
24+
* Can include callstack, system metadata, custom metadata, custom attribues and file attachments if needed,
25+
* Supports a wide range of unity version and environments,
26+
* Supports .NET 4.5 Backend, IL2CPP and Mono environments,
27+
* Supports offline database for error report storage and re-submission in case of network outage,
28+
* Fully customizable and extendable event handlers,
29+
* Custom IDE integrations.
30+
31+
# Prerequisites
32+
* Unity environment 2017.4.x
33+
* .NET 4.5 scripting runtime version,
34+
* Mono or IL2CPP scripting backend.
35+
36+
# Setup <a name="installation"></a>
37+
List of steps necessary to setup full Backtrace Unity integration.
38+
39+
## Installation guide
40+
* Download and unzip zip file with backtrace-unity support library,
41+
* Open your Unity project and paste unzipped library directory,
42+
* Your library is ready to use!
43+
44+
## Library configuration
45+
* Select scene object and add new component in inspector window,
46+
* Select `Backtrace Client` from insperctor search box,
47+
* `Backtrace Client` configuration window now waiting for configuration asset.
48+
![Backtrace configuration window](./images/unity-basic-configuration.PNG)
49+
* Right click on empty space in Unity workspace and select from the menu box `Backtrace > Configuration`. This option generate new empty asset file in your solution. You can drag and drop generated asset file into Backtrace Client configuration window.
50+
![Backtrace menu dialog box](./images/dialog-box.PNG)
51+
* Provide valid Backtrace client configuration and start using library!
52+
![Full Backtrace configuration](./images/client-setup.PNG)
53+
54+
**Field overview**
55+
* *Server url*: the url to Backtrace server instance. The user can start
56+
typing only their instance name (for example "my-bt-server"), and the plugin will guess
57+
the rest of the server url (for example "https://my-bt-server.sp.backtrace.io").
58+
59+
60+
* *Token*: Token to the Backtrace project instance. This field requires
61+
that the provided string has exactly **64** characters. If the developer doesn't
62+
know or doesn't have the access token, the plugin allows the user to browse
63+
tokens if the project name is available.
64+
65+
* *ReportsPerMinute*: Determine how many reports `Backtrace Unity` library should send per minute.
66+
67+
* *Handle unhandle exceptions*: Determine if library by default should handle unhandled exceptions.
68+
69+
70+
## Database support configuration
71+
Backtrace Unity integration allows to store on hard drive offline reports. `BacktraceDatabase` provide methods to save reports when you lost a connection.
72+
73+
To setup `BacktraceDatabase` configuraiton:
74+
* Select `Enable Database` checkbox in `Backtrace Client` configuration window,
75+
* Provide valid Backtrace database configuration and store offline reports in your game!
76+
![Full Backtrace database configuration](./images/database-setup.PNG)
77+
78+
79+
80+
81+
**Field overview**
82+
* `BacktraceDatabase` can use diffrent *Server url* *Token* *Reports per minute* and *Handle unhandled exceptions* values. These values are necessary if user want to send an offline reports to any `Backtrace` server,
83+
* *Backtrace Database path*: Path to directory where Backtrace database will store reports. Be aware! `Backtrace database` will remove all existing files on database start,
84+
* *Automatically send*: Determine if database should send automatically reports to `Backtrace` server,
85+
* *Create database directory*: Determine if library should create offline database directory if provided path doesn't exists,
86+
* *Maximum number of records*: Maximum number of stored reports in database. If value is equal to zero, then limit not exists,
87+
* *Maximum database size*: Maximum database size in MB. If value is equal to zero, then size is unlimited,
88+
* *Retry interval*: How much seconds library should wait before next retry,
89+
* *Maximum retries*: Maximum number of retries,
90+
* *RetryOrder*: Record order in database.
91+
92+
93+
## Web debugger result:
94+
![Web debugger](./images/web-debugger.PNG)
95+
96+
# Api overview
97+
98+
## Basic configuration
99+
If you setup `Backtrace client` and `Backtrace database` configuration you can retrieve database and client instances by using `GameObject`. When you retrieve client instance you can start sending reports from try/catch blok in your game!
100+
101+
```csharp
102+
103+
//Read from manager BacktraceClient instance
104+
var backtraceClient = GameObject.Find("manager name").GetComponent<BacktraceClient>();
105+
106+
//Read from manager BacktraceClient instance
107+
var database = GameObject.Find("manager name").GetComponent<BacktraceDatabase>();
108+
109+
110+
try{
111+
//throw exception here
112+
}
113+
catch(Exception exception){
114+
var report = new BacktraceReport(exception);
115+
backtraceClient.Send(report);
116+
}
117+
```
118+
119+
## Sending an error report <a name="documentation-sending-report"></a>
120+
121+
`BacktraceClient.Send` method will send an error report to the Backtrace endpoint specified. There `Send` method is overloaded, see examples below:
122+
123+
### Using BacktraceReport
124+
125+
The `BacktraceReport` class represents a single error report. (Optional) You can also submit custom attributes using the `attributes` parameter, or attach files by supplying an array of file paths in the `attachmentPaths` parameter.
126+
127+
```csharp
128+
try
129+
{
130+
//throw exception here
131+
}
132+
catch (Exception exception)
133+
{
134+
var report = new BacktraceReport(
135+
exception: exception,
136+
attributes: new Dictionary<string, object>() { { "key", "value" } },
137+
attachmentPaths: new List<string>() { @"file_path_1", @"file_path_2" }
138+
);
139+
backtraceClient.Send(backtraceReport);
140+
}
141+
```
142+
Notes:
143+
- if you setup `BacktraceClient` with `BacktraceDatabase` and your application is offline or you pass invalid credentials to `Backtrace server`, reports will be stored in database directory path,
144+
- `BacktraceReport` allows you to change default fingerprint generation algorithm. You can use `Fingerprint` property if you want to change fingerprint value. Keep in mind - fingerprint should be valid sha256 string.,
145+
- `BacktraceReport` allows you to change grouping strategy in Backtrace server. If you want to change how algorithm group your reports in Backtrace server please override `Factor` property.
146+
147+
If you want to use `Fingerprint` and `Factor` property you have to override default property values. See example below to check how to use these properties:
148+
149+
```csharp
150+
try
151+
{
152+
//throw exception here
153+
}
154+
catch (Exception exception)
155+
{
156+
var report = new BacktraceReport(...){
157+
FingerPrint = "sha256 string",
158+
Factor = exception.GetType().Name
159+
};
160+
....
161+
}
162+
163+
```
164+
165+
## Attaching custom event handlers <a name="documentation-events"></a>
166+
167+
`BacktraceClient` allows you to attach your custom event handlers. For example, you can trigger actions before the `Send` method:
168+
169+
```csharp
170+
171+
//Add your own handler to client API
172+
173+
backtraceClient.BeforeSend =
174+
(Model.BacktraceData model) =>
175+
{
176+
var data = model;
177+
//do something with data for example:
178+
data.Attributes.Add("eventAtrtibute", "EventAttributeValue");
179+
if(data.Classifier == null || !data.Classifier.Any())
180+
{
181+
data.Attachments.Add("path to attachment");
182+
}
183+
184+
return data;
185+
};
186+
```
187+
188+
`BacktraceClient` currently supports the following events:
189+
- `BeforeSend`
190+
- `OnClientReportLimitReached`
191+
- `OnServerResponse`
192+
- `OnServerError`
193+
194+
## Reporting unhandled application exceptions
195+
`BacktraceClient` supports reporting of unhandled application exceptions not captured by your try-catch blocks. To enable reporting of unhandled exceptions even if you dont set this option in `Backtrace configuration window` please use code below:
196+
```csharp
197+
backtraceClient.HandleApplicationException();
198+
```
199+
200+
## Flush database
201+
When your application starts, database can send stored offline reports. If you want to do make it manually you can use `Flush` method that allows you to send report to server and then remove it from hard drive. If `Send` method fails, database will no longer store data.
202+
203+
```csharp
204+
backtraceDatabase.Flush();
205+
```
206+
207+
## Clearing database
208+
You can clear all data from database without sending it to server by using `Clear` method. `BacktraceDatabase` will remove all files and won't send it to server.
209+
210+
```csharp
211+
backtraceDatabase.Clear();
212+
```
213+
214+
215+
# Architecture description
216+
217+
## BacktraceReport <a name="architecture-BacktraceReport"></a>
218+
**`BacktraceReport`** is a class that describe a single error report.
219+
220+
## BacktraceClient <a name="architecture-BacktraceClient"></a>
221+
**`BacktraceClient`** is a class that allows you to send `BacktraceReport` to `Backtrace` server by using `BacktraceApi`. This class sets up connection to the Backtrace endpoint and manages error reporting behavior (for example, saving minidump files on your local hard drive and limiting the number of error reports per minute). `BacktraceClient` inherits from `Mono behaviour`.
222+
223+
`BacktraceClient` requires from a `Backtrace configuration window`
224+
- `Sever url` - url to `Backtrace` server,
225+
- `Token` - token to `Backtrace` project,
226+
- `ReportPerMin` - A cap on the number of reports that can be sent per minute. If `ReportPerMin` is equal to zero then there is no cap.
227+
- `HandlUnhandleException` - flag that allows `BacktraceClient` handling unhandled exception by default.
228+
229+
## BacktraceData <a name="architecture-BacktraceData"></a>
230+
**`BacktraceData`** is a serializable class that holds the data to create a diagnostic JSON to be sent to the Backtrace endpoint via `BacktraceApi`. You can add additional pre-processors for `BacktraceData` by attaching an event handler to the `BacktraceClient.BeforeSend` event. `BacktraceData` require `BacktraceReport` and `BacktraceClient` client attributes.
231+
232+
## BacktraceApi <a name="architecture-BacktraceApi"></a>
233+
**`BacktraceApi`** is a class that sends diagnostic JSON to the Backtrace endpoint. `BacktraceApi` is instantiated when the `BacktraceClient` awake method is called. `BacktraceApi` can asynchronous reports to the Backtrace endpoint.
234+
235+
## BacktraceDatabase <a name="architecture-BacktraceDatabase"></a>
236+
**`BacktraceDatabase`** is a class that stores error report data in your local hard drive. `BacktraceDatabase` stores error reports that were not sent successfully due to network outage or server unavailability. `BacktraceDatabase` periodically tries to resend reports
237+
cached in the database. In `BacktraceDatabaseSettings` you can set the maximum number of entries (`Maximum retries`) to be stored in the database. The database will retry sending
238+
stored reports every `Retry interval` seconds up to `Retry limit` times, both customizable in the `Backtrace database configuration`.
239+
240+
`Backtrace database` has the following properties:
241+
- `Database path` - the local directory path where `BacktraceDatabase` stores error report data when reports fail to send,
242+
- `MaxRecordCount` - Maximum number of stored reports in Database. If value is equal to `0`, then there is no limit.
243+
- `MaxDatabaseSize` - Maximum database size in MB. If value is equal to `0`, there is no limit.
244+
- `AutoSendMode` - if the value is `true`, `BacktraceDatabase` will automatically try to resend stored reports. Default is `false`.
245+
- `RetryBehavior` -
246+
- `RetryBehavior.ByInterval` - Default. `BacktraceDatabase` will try to resend the reports every time interval specified by `RetryInterval`.
247+
- `RetryBehavior.NoRetry` - Will not attempt to resend reports
248+
- `RetryInterval` - the time interval between retries, in seconds.
249+
- `RetryLimit` - the maximum number of times `BacktraceDatabase` will attempt to resend error report before removing it from the database.
250+
251+
If you want to clear your database or remove all reports after send method you can use `Clear` and `Flush`.
252+
253+
## ReportWatcher <a name="architecture-ReportWatcher"></a>
254+
**`ReportWatcher`** is a class that validate send requests to the Backtrace endpoint. If `reportPerMin` is set in the `BacktraceClient` constructor call, `ReportWatcher` will drop error reports that go over the limit. `BacktraceClient` check rate limit before `BacktraceApi` generate diagnostic json.
255+
256+
257+
# Nice to know
258+
* Backtrace Unity integration use JSON.NET library to create diagnostic JSON. JSON.NET Source code is available in `src` directory.
259+
260+

src/JsonDotNet.meta renamed to images.meta

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

images/Backtrace.jpg

4.3 KB
Loading

images/Backtrace.jpg.meta

Lines changed: 76 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

images/client-setup.PNG

20.1 KB
Loading

0 commit comments

Comments
 (0)