Skip to content

Commit e7fd879

Browse files
Bartosz LitwiniukBartosz Litwiniuk
authored andcommitted
Initial commit
0 parents  commit e7fd879

File tree

66 files changed

+2133
-0
lines changed

Some content is hidden

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

66 files changed

+2133
-0
lines changed

.gitignore

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
*.class
2+
3+
# Mobile Tools for Java (J2ME)
4+
.mtj.tmp/
5+
6+
# Package Files #
7+
*.war
8+
*.ear
9+
10+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
11+
hs_err_pid*
12+
13+
local.properties
14+
build/
15+
.gradle/
16+
.idea
17+
*.iml

README.md

Lines changed: 185 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,185 @@
1+
# Backtrace
2+
[![Backtrace@release](https://img.shields.io/badge/Backtrace%40master-2.0.5-blue.svg)](https://www.nuget.org/packages/Backtrace)
3+
<!-- [![Build status](https://ci.appveyor.com/api/projects/status/o0n9sp0ydgxb3ktu?svg=true)](https://ci.appveyor.com/project/konraddysput/backtrace-csharp) -->
4+
5+
[![Backtrace@pre-release](https://img.shields.io/badge/Backtrace%40dev-2.0.6-blue.svg)](https://www.nuget.org/packages/Backtrace)
6+
<!-- [![Build status](https://ci.appveyor.com/api/projects/status/o0n9sp0ydgxb3ktu/branch/dev?svg=true)](https://ci.appveyor.com/project/konraddysput/backtrace-csharp/branch/dev) -->
7+
8+
9+
10+
[Backtrace](http://backtrace.io/)'s integration with Android applications written in Java allows customers to capture and report handled and unhandled java exceptions to their Backtrace instance, instantly offering the ability to prioritize and debug software errors.
11+
12+
13+
## Usage
14+
```java
15+
// replace with your endpoint url and token
16+
BacktraceCredentials credentials = new BacktraceCredentials("https://myserver.sp.backtrace.io:6097/", "4dca18e8769d0f5d10db0d1b665e64b3d716f76bf182fbcdad5d1d8070c12db0");
17+
BacktraceClient backtraceClient = new BacktraceClient(getApplicationContext(), credentials);
18+
19+
try {
20+
//throw exception here
21+
} catch (Exception exception) {
22+
backtraceClient.send(new BacktraceReport(e));
23+
}
24+
```
25+
26+
# Table of contents
27+
1. [Features Summary](#features-summary)
28+
2. [Supported SKDs](#supported-sdks)
29+
3. [Differences and limitations of the SDKs version](#limitations)
30+
4. [Installation](#installation)
31+
5. [Running sample application](#sample-app)
32+
6. [Documentation](#documentation)
33+
7. [Architecture](#architecture)
34+
35+
36+
# Features Summary <a name="features-summary"></a>
37+
* Light-weight Java client library that quickly submits exceptions and crashes to your Backtrace dashboard. Can include callstack, system metadata, custom metadata.<!--, and file attachments if needed.-->
38+
* Supports a wide range of Android SDKs.
39+
* Supports asynchronous Tasks.
40+
* Fully customizable and extendable event handlers and base classes for custom implementations.
41+
42+
# Differences and limitations of the SDKs version <a name="limitations"></a>
43+
44+
# Supported SDKs <a name="supported-sdks"></a>
45+
* Minimal SDK version 19 (Android 4.4)
46+
* Target SDK version 28 (Android 9.0)
47+
48+
# Installation <a name="installation"></a>
49+
TODO
50+
51+
# Running sample application
52+
## Android Studio <a name="sample-app-android-studio"></a>
53+
54+
- Open `MainActivity.java` class in **app\src\main\java\backtraceio\backtraceio** and replace `BacktraceCredential` constructor parameters with with your `Backtrace endpoint URL` (e.g. https://xxx.sp.backtrace.io:6098) and `submission token`:
55+
56+
```java
57+
BacktraceCredentials credentials = new BacktraceCredentials("https://myserver.sp.backtrace.io:6097/", "4dca18e8769d0f5d10db0d1b665e64b3d716f76bf182fbcdad5d1d8070c12db0");
58+
```
59+
60+
First start:
61+
- Press `Run` and `Run..` or type keys combination `Alt+Shift+F10`.
62+
- As module select `app` other options leave default.
63+
- Select `Run` and then select your emulator or connected device.
64+
- You should see new errors in your Backtrace instance. Refresh the Project page or Query Builder to see new details in real-time.
65+
66+
# Documentation <a name="documentation"></a>
67+
## Initialize a new BacktraceClient <a name="documentation-initialization"></a>
68+
69+
First create a `BacktraceCredential` instance with your `Backtrace endpoint URL` (e.g. https://xxx.sp.backtrace.io:6098) and `submission token`, and supply it as a parameter in the `BacktraceClient` constructor:
70+
71+
```java
72+
BacktraceCredentials credentials = new BacktraceCredentials("https://myserver.sp.backtrace.io:6097/", "4dca18e8769d0f5d10db0d1b665e64b3d716f76bf182fbcdad5d1d8070c12db0");
73+
BacktraceClient backtraceClient = new BacktraceClient(getApplicationContext(), credentials);
74+
```
75+
76+
## Sending an error report <a name="documentation-sending-report"></a>
77+
78+
Methods `BacktraceClient.send` and `BacktraceClient.sendAsync` will send an error report to the Backtrace endpoint specified. There `send` method is overloaded, see examples below:
79+
80+
81+
### Using BacktraceReport
82+
83+
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.-->
84+
85+
```java
86+
try {
87+
//throw exception here
88+
} catch (Exception exception) {
89+
BacktraceReport report = new BacktraceReport(e,
90+
new HashMap<String, Object>() {{
91+
put("key", "value");
92+
}}, new ArrayList<String>() {{
93+
add("file_path_1");
94+
add("file_path2");
95+
}});
96+
backtraceClient.send(report);
97+
}
98+
```
99+
100+
#### Asynchronous Send Support
101+
102+
Method `send` behind the mask use `AsyncTask` and wait until method `doInBackground` is not completed. Library gives you the option of not blocking code execution by using method `sendAsync` which returning the `AsyncTask<Void, Void, BacktraceResult>` object. Additionally, it is possible to specify the method that should be performed after completion `AsyncTask` by using events described in [events](#events).
103+
104+
105+
```java
106+
AsyncTask<Void, Void, BacktraceResult> sendAsyncTask = backtraceClient.sendAsync(report);
107+
// another code
108+
BacktraceResult result = sendAsyncTask.get();
109+
```
110+
111+
### Other BacktraceReport Overloads
112+
113+
`BacktraceClient` can also automatically create `BacktraceReport` given an exception or a custom message using the following overloads of the `BacktraceClient.send` or `BacktraceClient.sendAsync` methods:
114+
115+
```java
116+
try {
117+
//throw exception here
118+
} catch (Exception exception) {
119+
120+
backtraceClient.Send(report);
121+
122+
//pass exception to Send method
123+
backtraceClient.Send(exception);
124+
125+
//pass your custom message to Send method
126+
backtraceClient.SendAsync("Message");
127+
}
128+
```
129+
130+
## Attaching custom event handlers <a name="documentation-events"></a>
131+
132+
All events are written in *listener* pattern. `BacktraceClient` allows you to attach your custom event handlers. For example, you can trigger actions before the `send` method:
133+
134+
```java
135+
backtraceClient.setOnBeforeSendEventListener(new OnBeforeSendEventListener() {
136+
@Override
137+
public BacktraceData onEvent(BacktraceData data) {
138+
// another code
139+
return data;
140+
}
141+
});
142+
```
143+
144+
`BacktraceClient` currently supports the following events:
145+
- `BeforeSend`
146+
- `AfterSend`
147+
- `RequestHandler`
148+
- `OnServerResponse`
149+
- `OnServerError`
150+
151+
152+
## Reporting unhandled application exceptions
153+
`BacktraceClient` also supports reporting of unhandled application exceptions not captured by your try-catch blocks. To enable reporting of unhandled exceptions:
154+
```java
155+
new BacktraceExceptionHandler(getApplicationContext(), backtraceClient);
156+
```
157+
158+
## Custom client and report classes <a name="documentation-customization"></a>
159+
160+
You can extend `BacktraceBase` to create your own Backtrace client and error report implementation. You can refer to `BacktraceClient` for implementation inspirations.
161+
162+
# Architecture <a name="architecture"></a>
163+
164+
## BacktraceReport <a name="architecture-BacktraceReport"></a>
165+
**`BacktraceReport`** is a class that describe a single error report.
166+
167+
## BacktraceClient <a name="architecture-BacktraceClient"></a>
168+
**`BacktraceClient`** is a class that allows you to instantiate a client instance that interacts with `BacktraceApi`. This class sets up connection to the Backtrace endpoint and manages error reporting behavior. `BacktraceClient` extends `BacktraceBase` class.
169+
170+
## BacktraceData <a name="architecture-BacktraceData"></a>
171+
**`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.setOnBeforeSendEventListener(event)` event. `BacktraceData` require `BacktraceReport` and `BacktraceClient` client attributes.
172+
173+
## BacktraceApi <a name="architecture-BacktraceApi"></a>
174+
**`BacktraceApi`** is a class that sends diagnostic JSON to the Backtrace endpoint. `BacktraceApi` is instantiated when the `BacktraceClient` constructor is called. You use the following event handlers in `BacktraceApi` to customize how you want to handle JSON data:
175+
- `RequestHandler` - attach an event handler to this event to override the default `BacktraceApi.send` method. <!--A `RequestHandler` TODO -->
176+
- `OnServerError` - attach an event handler to be invoked when the server returns with a `400 bad request`, `401 unauthorized` or other HTTP error codes. <!-- TODO -->
177+
- `OnServerResponse` - attach an event handler to be invoked when the server returns with a valid response.
178+
179+
180+
## BacktraceResult <a name="architecture-BacktraceResult"></a>
181+
**`BacktraceResult`** is a class that holds response and result from a `send` or `sendAsync` call. The class contains a `Status` property that indicates whether the call was completed (`OK`), the call returned with an error (`ServerError`), . Additionally, the class has a `Message` property that contains details about the status.
182+
183+
184+
185+

backtrace-library/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

backtrace-library/build.gradle

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
apply plugin: 'com.android.library'
2+
3+
android {
4+
compileSdkVersion 28
5+
6+
defaultConfig {
7+
minSdkVersion 19
8+
targetSdkVersion 28
9+
versionCode 1
10+
versionName "1.0"
11+
12+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13+
14+
}
15+
16+
buildTypes {
17+
release {
18+
minifyEnabled false
19+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20+
}
21+
}
22+
23+
}
24+
25+
dependencies {
26+
implementation fileTree(dir: 'libs', include: ['*.jar'])
27+
implementation 'com.google.code.gson:gson:2.8.5'
28+
implementation 'com.android.support:appcompat-v7:28.0.0'
29+
testImplementation 'junit:junit:4.12'
30+
androidTestImplementation 'com.android.support.test:runner:1.0.2'
31+
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
32+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package backtraceio.library;
2+
3+
import android.content.Context;
4+
import android.support.test.InstrumentationRegistry;
5+
import android.support.test.runner.AndroidJUnit4;
6+
7+
import org.junit.Test;
8+
import org.junit.runner.RunWith;
9+
10+
import static org.junit.Assert.*;
11+
12+
/**
13+
* Instrumented test, which will execute on an Android device.
14+
*
15+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
16+
*/
17+
@RunWith(AndroidJUnit4.class)
18+
public class ExampleInstrumentedTest {
19+
@Test
20+
public void useAppContext() {
21+
// Context of the app under test.
22+
Context appContext = InstrumentationRegistry.getTargetContext();
23+
24+
assertEquals("backtraceio.library.test", appContext.getPackageName());
25+
}
26+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
package="backtraceio.library">
3+
4+
</manifest>
5+
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package backtraceio.library;
2+
3+
import android.content.Context;
4+
import android.os.AsyncTask;
5+
6+
import backtraceio.library.models.BacktraceData;
7+
import backtraceio.library.models.BacktraceResult;
8+
import backtraceio.library.models.base.BacktraceBase;
9+
import backtraceio.library.models.json.BacktraceReport;
10+
11+
public class BacktraceClient extends BacktraceBase {
12+
private BacktraceCredentials backtraceCredentials;
13+
14+
public BacktraceClient(Context context, BacktraceCredentials credentials)
15+
{
16+
super(context, credentials);
17+
}
18+
19+
public BacktraceResult send(String message)
20+
{
21+
return super.send(message);
22+
}
23+
24+
public BacktraceResult send(Exception e)
25+
{
26+
return super.send(e);
27+
}
28+
29+
public BacktraceResult send(BacktraceReport report)
30+
{
31+
return super.send(report);
32+
}
33+
34+
public AsyncTask<Void, Void, BacktraceResult> sendAsync(String message)
35+
{
36+
return super.sendAsync(message);
37+
}
38+
39+
public AsyncTask<Void, Void, BacktraceResult> sendAsync(Exception e)
40+
{
41+
return super.sendAsync(e);
42+
}
43+
44+
public AsyncTask<Void, Void, BacktraceResult> sendAsync(BacktraceReport report)
45+
{
46+
return super.sendAsync(report);
47+
}
48+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package backtraceio.library;
2+
3+
import android.util.Log;
4+
5+
public class BacktraceCredentials {
6+
private String TAG = "BACKTRACE.IO";
7+
private String endpointUrl;
8+
private String submissionToken;
9+
10+
public String getEndpointUrl() {
11+
return endpointUrl;
12+
}
13+
14+
public String getSubmissionToken() {
15+
return submissionToken;
16+
}
17+
18+
public BacktraceCredentials(String endpointUrl, String submissionToken)
19+
{
20+
this.endpointUrl = endpointUrl;
21+
this.submissionToken = submissionToken;
22+
Log.d(TAG, endpointUrl);
23+
}
24+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package backtraceio.library;
2+
3+
public class BacktraceException extends Exception {
4+
5+
}

0 commit comments

Comments
 (0)