Skip to content

Commit 752d748

Browse files
Merge pull request #316 from bugsnag/next
Next release
2 parents f9a8e91 + 48a807f commit 752d748

38 files changed

Lines changed: 760 additions & 212 deletions

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
# Changelog
22

3+
## 4.4.0 (2018-05-17)
4+
5+
### Features
6+
7+
Deprecation notice:
8+
9+
SessionTrackingApiClient and ErrorApiClient are now deprecated in favour of the Delivery interface.
10+
If you configure a custom HTTP client with Bugsnag, it is recommended that you migrate over to this new API.
11+
Further information is available [in the docs.](https://docs.bugsnag.com/platforms/android/sdk/configuration-options/).
12+
13+
* Expose Delivery API interface for configuring custom HTTP clients
14+
[#299](https://github.com/bugsnag/bugsnag-android/pull/299)
15+
16+
### Enhancements
17+
18+
* Use buffered streams for IO (perf improvement)
19+
[#307](https://github.com/bugsnag/bugsnag-android/pull/307)
20+
21+
322
## 4.3.4 (2018-05-02)
423

524
### Bug fixes

Gemfile.lock

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
GIT
22
remote: git@github.com:bugsnag/maze-runner
3-
revision: 65bdcb7a135ef0a5864d03c454f7a1654f850237
3+
revision: f7123450d5a75b719911c6dd3baa0507e6062c2d
44
specs:
55
bugsnag-maze-runner (1.0.0)
66
cucumber (~> 3.1.0)
7+
cucumber-expressions (= 5.0.15)
78
minitest (~> 5.0)
89
rack (~> 2.0.0)
910
test-unit (~> 3.2.0)
1011

1112
GEM
1213
remote: https://rubygems.org/
1314
specs:
14-
backports (3.11.1)
15+
backports (3.11.3)
1516
builder (3.2.3)
1617
coderay (1.1.2)
1718
cucumber (3.1.0)
@@ -27,7 +28,7 @@ GEM
2728
backports (>= 3.8.0)
2829
cucumber-tag_expressions (~> 1.1.0)
2930
gherkin (>= 5.0.0)
30-
cucumber-expressions (5.0.13)
31+
cucumber-expressions (5.0.15)
3132
cucumber-tag_expressions (1.1.1)
3233
cucumber-wire (0.0.1)
3334
diff-lcs (1.3)
@@ -40,7 +41,7 @@ GEM
4041
pry (0.11.3)
4142
coderay (~> 1.1.0)
4243
method_source (~> 0.9.0)
43-
rack (2.0.4)
44+
rack (2.0.5)
4445
test-unit (3.2.7)
4546
power_assert
4647

features/custom_client.feature

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
Feature: Using custom API clients for reporting errors
2+
3+
Scenario: Set a custom session client and flush a stored session
4+
When I run "CustomClientSessionFlushScenario" with the defaults
5+
When I force stop the "com.bugsnag.android.mazerunner" Android app
6+
And I set environment variable "EVENT_TYPE" to "CustomClientSessionFlushScenario"
7+
And I set environment variable "EVENT_METADATA" to "DeliverSessions"
8+
And I start the "com.bugsnag.android.mazerunner" Android app using the "com.bugsnag.android.mazerunner.MainActivity" activity
9+
Then I should receive 2 requests
10+
And the "Custom-Client" header equals "Hello World" for request 0
11+
And the "Custom-Client" header equals "Hello World" for request 1
12+
13+
Scenario: Set a custom error API client and notify an error
14+
When I run "CustomClientErrorScenario" with the defaults
15+
Then I should receive 1 request
16+
And the "Custom-Client" header equals "Hello World"
17+
And the request is a valid for the error reporting API
18+
19+
Scenario: Set a custom session API client and start a session
20+
When I run "CustomClientSessionScenario" with the defaults
21+
Then I should receive 1 request
22+
And the "Custom-Client" header equals "Hello World"
23+
And the request is a valid for the session tracking API
24+
25+
Scenario: Set a custom error client and flush a stored error
26+
When I run "CustomClientErrorFlushScenario" with the defaults
27+
When I force stop the "com.bugsnag.android.mazerunner" Android app
28+
And I set environment variable "EVENT_TYPE" to "CustomClientErrorFlushScenario"
29+
And I set environment variable "EVENT_METADATA" to "DeliverReports"
30+
And I start the "com.bugsnag.android.mazerunner" Android app using the "com.bugsnag.android.mazerunner.MainActivity" activity
31+
Then I should receive 1 request
32+
And the "Custom-Client" header equals "Hello World"

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ org.gradle.jvmargs=-Xmx1536m
1111
# This option should only be used with decoupled projects. More details, visit
1212
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
1313
# org.gradle.parallel=true
14-
VERSION_NAME=4.3.4
14+
VERSION_NAME=4.4.0
1515
GROUP=com.bugsnag
1616
POM_SCM_URL=https://github.com/bugsnag/bugsnag-android
1717
POM_SCM_CONNECTION=scm:git@github.com:bugsnag/bugsnag-android.git

mazerunner/src/main/java/com/bugsnag/android/TestHarnessHooks.kt

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package com.bugsnag.android
22

33
import android.content.Context
44
import android.net.ConnectivityManager
5-
import com.bugsnag.android.Bugsnag.client
65

76
/**
87
* Accesses the session tracker and flushes all stored sessions
@@ -11,31 +10,62 @@ internal fun flushAllSessions() {
1110
Bugsnag.getClient().sessionTracker.flushStoredSessions()
1211
}
1312

14-
internal fun flushErrorStoreAsync(client: Client, apiClient: ErrorReportApiClient) {
15-
client.errorStore.flushAsync(apiClient)
13+
internal fun flushErrorStoreAsync(client: Client) {
14+
client.errorStore.flushAsync()
1615
}
1716

18-
internal fun flushErrorStoreOnLaunch(client: Client, apiClient: ErrorReportApiClient) {
19-
client.errorStore.flushOnLaunch(apiClient)
17+
internal fun flushErrorStoreOnLaunch(client: Client) {
18+
client.errorStore.flushOnLaunch()
2019
}
2120

2221
/**
23-
* Creates an error API client with a 500ms delay, emulating poor network connectivity
22+
* Creates a delivery API client with a 500ms delay, emulating poor network connectivity
2423
*/
25-
internal fun createSlowErrorApiClient(context: Context): ErrorReportApiClient {
24+
internal fun createSlowDelivery(context: Context): Delivery {
2625
val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager?
27-
val defaultHttpClient = DefaultHttpClient(cm)
28-
29-
return ErrorReportApiClient({ url: String?,
30-
report: Report?,
31-
headers: MutableMap<String, String>? ->
32-
Thread.sleep(500)
33-
defaultHttpClient.postReport(url, report, headers)
34-
})
26+
val delivery = DefaultDelivery(cm)
27+
28+
return object : Delivery {
29+
override fun deliver(payload: SessionTrackingPayload?, config: Configuration?) {
30+
Thread.sleep(500)
31+
delivery.deliver(payload, config)
32+
}
33+
34+
override fun deliver(report: Report?, config: Configuration?) {
35+
Thread.sleep(500)
36+
delivery.deliver(report, config)
37+
}
38+
}
39+
}
40+
41+
internal fun createDefaultDelivery(context: Context): DefaultDelivery {
42+
val cm = context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager?
43+
return DefaultDelivery(cm)
44+
}
45+
46+
internal fun createCustomHeaderDelivery(context: Context): Delivery {
47+
return object : Delivery {
48+
val delivery: DefaultDelivery = createDefaultDelivery(context)
49+
50+
override fun deliver(payload: SessionTrackingPayload?, config: Configuration?) {
51+
deliver(config?.sessionEndpoint, payload, config?.sessionApiHeaders)
52+
}
53+
54+
override fun deliver(report: Report?, config: Configuration?) {
55+
deliver(config?.endpoint, report, config?.errorApiHeaders)
56+
}
57+
58+
fun deliver(endpoint: String?,
59+
streamable: JsonStream.Streamable?,
60+
headers: MutableMap<String, String>?) {
61+
headers!!["Custom-Client"] = "Hello World"
62+
delivery.deliver(endpoint, streamable, headers)
63+
}
64+
}
3565
}
3666

67+
3768
internal fun writeErrorToStore(client: Client) {
3869
val error = Error.Builder(Configuration("api-key"), RuntimeException(), null).build()
3970
client.errorStore.write(error)
4071
}
41-

mazerunner/src/main/java/com/bugsnag/android/mazerunner/scenarios/AsyncErrorConnectivityScenario.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ internal class AsyncErrorConnectivityScenario(config: Configuration,
1111
context: Context) : Scenario(config, context) {
1212

1313
override fun run() {
14+
val delivery = createSlowDelivery(context)
15+
config.delivery = delivery
1416
super.run()
15-
val apiClient = createSlowErrorApiClient(context)
16-
Bugsnag.setErrorReportApiClient(apiClient)
1717

1818
writeErrorToStore(Bugsnag.getClient())
19-
flushErrorStoreAsync(Bugsnag.getClient(), apiClient)
20-
flushErrorStoreOnLaunch(Bugsnag.getClient(), apiClient)
19+
flushErrorStoreAsync(Bugsnag.getClient())
20+
flushErrorStoreOnLaunch(Bugsnag.getClient())
2121
Thread.sleep(50)
2222
}
2323

mazerunner/src/main/java/com/bugsnag/android/mazerunner/scenarios/AsyncErrorDoubleFlushScenario.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ internal class AsyncErrorDoubleFlushScenario(config: Configuration,
1111
context: Context) : Scenario(config, context) {
1212

1313
override fun run() {
14+
config.delivery = createSlowDelivery(context)
1415
super.run()
15-
val apiClient = createSlowErrorApiClient(context)
16-
Bugsnag.setErrorReportApiClient(apiClient)
1716

1817
writeErrorToStore(Bugsnag.getClient())
19-
flushErrorStoreAsync(Bugsnag.getClient(), apiClient)
20-
flushErrorStoreAsync(Bugsnag.getClient(), apiClient)
18+
flushErrorStoreAsync(Bugsnag.getClient())
19+
flushErrorStoreAsync(Bugsnag.getClient())
2120
Thread.sleep(50)
2221
}
2322

mazerunner/src/main/java/com/bugsnag/android/mazerunner/scenarios/AsyncErrorLaunchScenario.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,12 @@ internal class AsyncErrorLaunchScenario(config: Configuration,
1111
context: Context) : Scenario(config, context) {
1212

1313
override fun run() {
14+
config.delivery = createSlowDelivery(context)
1415
super.run()
15-
val apiClient = createSlowErrorApiClient(context)
16-
Bugsnag.setErrorReportApiClient(apiClient)
1716

1817
writeErrorToStore(Bugsnag.getClient())
19-
flushErrorStoreOnLaunch(Bugsnag.getClient(), apiClient)
20-
flushErrorStoreAsync(Bugsnag.getClient(), apiClient)
18+
flushErrorStoreOnLaunch(Bugsnag.getClient())
19+
flushErrorStoreAsync(Bugsnag.getClient())
2120
Thread.sleep(50)
2221
}
2322

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.bugsnag.android.mazerunner.scenarios
2+
3+
import android.content.Context
4+
import com.bugsnag.android.Bugsnag
5+
import com.bugsnag.android.Configuration
6+
import com.bugsnag.android.createCustomHeaderDelivery
7+
8+
/**
9+
* Sends an unhandled exception which is cached on disk to Bugsnag, then sent on a separate launch,
10+
* using a custom API client which modifies the request.
11+
*/
12+
internal class CustomClientErrorFlushScenario(config: Configuration,
13+
context: Context) : Scenario(config, context) {
14+
15+
override fun run() {
16+
if ("DeliverReports" == eventMetaData) {
17+
config.delivery = createCustomHeaderDelivery(context)
18+
}
19+
super.run()
20+
21+
if ("DeliverReports" != eventMetaData) {
22+
disableAllDelivery()
23+
throw RuntimeException("ReportCacheScenario")
24+
}
25+
26+
}
27+
28+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.bugsnag.android.mazerunner.scenarios
2+
3+
import android.content.Context
4+
import com.bugsnag.android.Bugsnag
5+
import com.bugsnag.android.Configuration
6+
import com.bugsnag.android.createCustomHeaderDelivery
7+
8+
/**
9+
* Sends a handled exception to Bugsnag using a custom API client which modifies the request.
10+
*/
11+
internal class CustomClientErrorScenario(config: Configuration,
12+
context: Context) : Scenario(config, context) {
13+
14+
override fun run() {
15+
config.delivery = createCustomHeaderDelivery(context)
16+
super.run()
17+
Bugsnag.notify(RuntimeException("Hello"))
18+
}
19+
20+
}

0 commit comments

Comments
 (0)