Skip to content

Commit 3f970f1

Browse files
Merge branch 'master' into dev
# Conflicts: # backtrace-library/build.gradle
2 parents 9fa9938 + 81daf21 commit 3f970f1

File tree

1 file changed

+83
-10
lines changed

1 file changed

+83
-10
lines changed

README.md

Lines changed: 83 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,33 @@
1515

1616

1717
## Usage
18+
Java
1819
```java
1920
// replace with your endpoint url and token
2021
BacktraceCredentials credentials = new BacktraceCredentials("<endpoint-url>", "<token>");
2122
BacktraceClient backtraceClient = new BacktraceClient(getApplicationContext(), credentials);
2223

2324
try {
24-
//throw exception here
25+
// throw exception here
2526
} catch (Exception exception) {
2627
backtraceClient.send(new BacktraceReport(e));
2728
}
2829
```
2930

31+
Kotlin
32+
```kotlin
33+
// replace with your endpoint url and token
34+
val backtraceCredentials = BacktraceCredentials("<endpoint-url>", "<token>")
35+
val backtraceClient = BacktraceClient(applicationContext, backtraceCredentials)
36+
37+
try {
38+
// throw exception here
39+
}
40+
catch (e: Exception) {
41+
backtraceClient.send(BacktraceReport(e))
42+
}
43+
```
44+
3045
# Table of contents
3146
1. [Features Summary](#features-summary)
3247
2. [Supported SKDs](#supported-sdks)
@@ -41,7 +56,7 @@ try {
4156
Gradle
4257
```
4358
dependencies {
44-
compile 'com.github.backtrace-labs.backtrace-android:backtrace-library:1.0rc1'
59+
implementation 'com.github.backtrace-labs.backtrace-android:backtrace-library:1.0'
4560
}
4661
```
4762

@@ -50,7 +65,7 @@ Maven
5065
<dependency>
5166
<groupId>com.github.backtrace-labs.backtrace-android</groupId>
5267
<artifactId>backtrace-library</artifactId>
53-
<version>1.0rc1</version>
68+
<version>1.0</version>
5469
<type>aar</type>
5570
</dependency>
5671
```
@@ -76,10 +91,16 @@ TODO
7691

7792
- Open `MainActivity.java` class in **app\src\main\java\backtraceio\backtraceio** and replace `BacktraceCredential` constructor parameters with your `Backtrace endpoint URL` (e.g. https://xxx.sp.backtrace.io:6098) and `submission token`:
7893

94+
Java
7995
```java
8096
BacktraceCredentials credentials = new BacktraceCredentials("https://myserver.sp.backtrace.io:6097/", "4dca18e8769d0f5d10db0d1b665e64b3d716f76bf182fbcdad5d1d8070c12db0");
8197
```
8298

99+
Kotlin
100+
```kotlin
101+
val backtraceCredentials = BacktraceCredentials("https://myserver.sp.backtrace.io:6097/", "4dca18e8769d0f5d10db0d1b665e64b3d716f76bf182fbcdad5d1d8070c12db0")
102+
```
103+
83104
First start:
84105
- Press `Run` and `Run..` or type keys combination `Alt+Shift+F10`.
85106
- As module select `app` other options leave default.
@@ -91,11 +112,18 @@ First start:
91112

92113
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:
93114

115+
Java
94116
```java
95117
BacktraceCredentials credentials = new BacktraceCredentials("https://myserver.sp.backtrace.io:6097/", "4dca18e8769d0f5d10db0d1b665e64b3d716f76bf182fbcdad5d1d8070c12db0");
96118
BacktraceClient backtraceClient = new BacktraceClient(getApplicationContext(), credentials);
97119
```
98120

121+
Kotlin
122+
```kotlin
123+
val backtraceCredentials = BacktraceCredentials("https://myserver.sp.backtrace.io:6097/", "4dca18e8769d0f5d10db0d1b665e64b3d716f76bf182fbcdad5d1d8070c12db0")
124+
val backtraceClient = BacktraceClient(applicationContext, backtraceCredentials)
125+
```
126+
99127
## Sending an error report <a name="documentation-sending-report"></a>
100128

101129
Methods `BacktraceClient.send` and `BacktraceClient.sendAsync` will send an error report to the Backtrace endpoint specified. There `send` method is overloaded, see examples below:
@@ -105,9 +133,10 @@ Methods `BacktraceClient.send` and `BacktraceClient.sendAsync` will send an erro
105133

106134
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.-->
107135

136+
Java
108137
```java
109138
try {
110-
//throw exception here
139+
// throw exception here
111140
} catch (Exception exception) {
112141
BacktraceReport report = new BacktraceReport(e,
113142
new HashMap<String, Object>() {{
@@ -120,40 +149,76 @@ try {
120149
}
121150
```
122151

152+
Kotlin
153+
```kotlin
154+
try {
155+
// throw exception here
156+
}
157+
catch (e: Exception) {
158+
val report = BacktraceReport(e, mapOf("key" to "value"), listOf("file_path_1", "file_path_2"))
159+
backtraceClient.send(report)
160+
}
161+
```
162+
123163
#### Asynchronous Send Support
124164

125165
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).
126166

127167

168+
Java
128169
```java
129170
AsyncTask<Void, Void, BacktraceResult> sendAsyncTask = backtraceClient.sendAsync(report);
130171
// another code
131172
BacktraceResult result = sendAsyncTask.get();
132173
```
133174

175+
Kotlin
176+
```kotlin
177+
val sendAsyncTask = backtraceClient.sendAsync(report)
178+
// another code
179+
val result = asynctask.get()
180+
```
181+
134182
### Other BacktraceReport Overloads
135183

136184
`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:
137185

186+
Java
138187
```java
139188
try {
140-
//throw exception here
189+
// throw exception here
141190
} catch (Exception exception) {
142191

143-
backtraceClient.Send(report);
192+
backtraceClient.send(new BacktraceReport(exception));
193+
194+
// pass exception to Send method
195+
backtraceClient.send(exception);
196+
197+
// pass your custom message to Send method
198+
backtraceClient.sendAsync("Message");
199+
}
200+
```
201+
Kotlin
202+
```kotlin
203+
try {
204+
// throw exception here
205+
} catch (exception: Exception) {
206+
backtraceClient.send(BacktraceReport(exception));
144207

145-
//pass exception to Send method
146-
backtraceClient.Send(exception);
208+
// pass exception to Send method
209+
backtraceClient.send(exception);
147210

148-
//pass your custom message to Send method
149-
backtraceClient.SendAsync("Message");
211+
// pass your custom message to Send method
212+
backtraceClient.sendAsync("Message");
150213
}
151214
```
152215

216+
153217
## Attaching custom event handlers <a name="documentation-events"></a>
154218

155219
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:
156220

221+
Java
157222
```java
158223
backtraceClient.setOnBeforeSendEventListener(new OnBeforeSendEventListener() {
159224
@Override
@@ -164,6 +229,14 @@ backtraceClient.setOnBeforeSendEventListener(new OnBeforeSendEventListener() {
164229
});
165230
```
166231

232+
Kotlin
233+
```kotlin
234+
backtraceClient.setOnBeforeSendEventListener { data ->
235+
// another code
236+
data
237+
}
238+
```
239+
167240
`BacktraceClient` currently supports the following events:
168241
- `BeforeSend`
169242
- `AfterSend`

0 commit comments

Comments
 (0)