Skip to content

Commit

Permalink
Merge pull request #1593 from bugsnag/v5.19.2
Browse files Browse the repository at this point in the history
v5.19.2
  • Loading branch information
lemnik authored Jan 31, 2022
2 parents 362e0f7 + 6ebcfc2 commit da43423
Show file tree
Hide file tree
Showing 12 changed files with 157 additions and 4 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# Changelog

## 5.19.2 (2022-01-31)

### Bug fixes

* Fixed an issue where feature-flags were not always sent if an OnSendCallback was configured
[#1589](https://github.com/bugsnag/bugsnag-android/pull/1589)

* Fix a bug where api keys set in React Native callbacks were ignored
[#1592](https://github.com/bugsnag/bugsnag-android/pull/1592)

## 5.19.1 (2022-01-21)

### Bug fixes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ internal class BugsnagEventMapper(
event.addMetadata(key, value)
}

val featureFlagsList: List<Map<String, Any?>> = map.readEntry("featureFlags")
featureFlagsList.forEach { featureFlagMap ->
event.addFeatureFlag(
featureFlagMap.readEntry("featureFlag"),
featureFlagMap["variant"] as? String
)
}

// populate breadcrumbs
val breadcrumbList: List<MutableMap<String, Any?>> = map.readEntry("breadcrumbs")
breadcrumbList.mapTo(event.breadcrumbs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import java.io.IOException
*/
class Notifier @JvmOverloads constructor(
var name: String = "Android Bugsnag Notifier",
var version: String = "5.19.1",
var version: String = "5.19.2",
var url: String = "https://bugsnag.com"
) : JsonStream.Streamable {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,12 @@ internal class EventSerializationTest {
Error(ErrorInternal("WhoopsException", "Whoops", stacktrace), NoopLogger)
it.errors.clear()
it.errors.add(err)
},

// featureFlags included
createEvent {
it.addFeatureFlag("no_variant")
it.addFeatureFlag("flag", "with_variant")
}
)
}
Expand Down
45 changes: 45 additions & 0 deletions bugsnag-android-core/src/test/resources/event_serialization_7.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"metaData": {},
"severity": "warning",
"severityReason": {
"type": "handledException",
"unhandledOverridden": false
},
"unhandled": false,
"exceptions": [],
"projectPackages": [
"com.example.foo"
],
"user": {},
"app": {
"type": "android",
"versionCode": 0
},
"device": {
"cpuAbi": [],
"manufacturer": "samsung",
"model": "s7",
"osName": "android",
"osVersion": "7.1",
"runtimeVersions": {
"osBuild": "bulldog",
"androidApiLevel": "24"
},
"totalMemory": 109230923452,
"freeDisk": 22234423124,
"freeMemory": 92340255592,
"orientation": "portrait",
"time": "1970-01-01T00:00:00.000Z"
},
"breadcrumbs": [],
"threads": [],
"featureFlags": [
{
"featureFlag": "no_variant"
},
{
"featureFlag": "flag",
"variant": "with_variant"
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ internal class EventDeserializer(
event.context = map["context"] as String?
event.groupingHash = map["groupingHash"] as String?

// apiKey if it exists in the map and is not empty
val apiKey = (map["apiKey"] as? String)?.takeIf { it.isNotEmpty() }
apiKey?.let { event.apiKey = apiKey }

// app/device
event.app = appDeserializer.deserialize(map["app"] as MutableMap<String, Any>)
event.device = deviceDeserializer.deserialize(map["device"] as MutableMap<String, Any>)
Expand All @@ -62,7 +66,8 @@ internal class EventDeserializer(
if (map.containsKey("nativeStack") && event.errors.isNotEmpty()) {
runCatching {
val jsError = event.errors.first()
val nativeStackDeserializer = NativeStackDeserializer(projectPackages, client.config)
val nativeStackDeserializer =
NativeStackDeserializer(projectPackages, client.config)
val nativeStack = nativeStackDeserializer.deserialize(map)
jsError.stacktrace.addAll(0, nativeStack)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class EventDeserializerTest {
assertEquals("app-id", event.app.id)
assertEquals("device-id", event.device.id)
assertEquals("123", event.getMetadata("custom", "id"))
assertEquals(TestData.generateConfig().apiKey, event.apiKey)
}

@Test
Expand All @@ -115,4 +116,30 @@ class EventDeserializerTest {
assertFalse(event.isUnhandled)
assertTrue(TestHooks.getUnhandledOverridden(event))
}

@Test
fun deserializeApiKeyOverridden() {
val map: MutableMap<String, Any?> = hashMapOf(
"apiKey" to "abc123",
"severity" to "info",
"user" to mapOf("id" to "123"),
"unhandled" to false,
"severityReason" to hashMapOf(
"type" to "unhandledException",
"unhandledOverridden" to true
),
"breadcrumbs" to listOf(breadcrumbMap()),
"threads" to listOf(threadMap()),
"errors" to listOf(errorMap()),
"metadata" to metadataMap(),
"app" to mapOf("id" to "app-id"),
"device" to mapOf(
"id" to "device-id",
"runtimeVersions" to hashMapOf<String, Any>()
)
)

val event = EventDeserializer(client, emptyList()).deserialize(map)
assertEquals("abc123", event.apiKey)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import com.bugsnag.android.Bugsnag;
import com.bugsnag.android.Configuration;
import com.bugsnag.android.Event;
import com.bugsnag.android.FeatureFlag;
import com.bugsnag.android.OnSendCallback;

import android.content.Context;

Expand All @@ -18,10 +20,21 @@ public class CXXFeatureFlagNativeCrashScenario extends Scenario {

public native void crash();

/**
*/
public CXXFeatureFlagNativeCrashScenario(@NonNull Configuration config,
@NonNull Context context,
@Nullable String eventMetadata) {
super(config, context, eventMetadata);

if (getEventMetadata() != null && getEventMetadata().contains("onsend")) {
config.addOnSend(new OnSendCallback() {
public boolean onSend(@NonNull Event event) {
event.addFeatureFlag("on_send_callback");
return true;
}
});
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,18 @@ import com.bugsnag.android.FeatureFlag
class FeatureFlagScenario(
config: Configuration,
context: Context,
eventMetadata: String
eventMetadata: String?
) : Scenario(config, context, eventMetadata) {

init {
if (eventMetadata?.contains("onsend") == true) {
config.addOnSend { event ->
event.addFeatureFlag("on_send_callback")
return@addOnSend true
}
}
}

override fun startScenario() {
super.startScenario()

Expand Down
13 changes: 13 additions & 0 deletions features/full_tests/feature_flags.feature
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,16 @@ Scenario: Sends no feature flags after clearFeatureFlags()
And the exception "errorClass" equals "java.lang.RuntimeException"
And the event "unhandled" is false
And event 0 has no feature flags

Scenario: Sends feature flags added in OnSend Callbacks
When I configure the app to run in the "onsend" state
And I run "FeatureFlagScenario" and relaunch the app
And I configure Bugsnag for "FeatureFlagScenario"
Then I wait to receive an error
And the exception "errorClass" equals "java.lang.RuntimeException"
And the event "unhandled" is false
And event 0 contains the feature flag "demo_mode" with no variant
And event 0 contains the feature flag "on_send_callback" with no variant
And event 0 does not contain the feature flag "should_not_be_reported_1"
And event 0 does not contain the feature flag "should_not_be_reported_2"
And event 0 does not contain the feature flag "should_not_be_reported_3"
16 changes: 16 additions & 0 deletions features/full_tests/native_feature_flags.feature
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,19 @@ Feature: Synchronizing feature flags to the native layer
| SIGILL |
| SIGTRAP |
And event 0 has no feature flags

Scenario: Sends feature flags added in OnSend Callbacks
When I run "CXXFeatureFlagNativeCrashScenario"
And I relaunch the app after a crash
And I configure the app to run in the "onsend" state
And I configure Bugsnag for "CXXFeatureFlagNativeCrashScenario"
Then I wait to receive an error
And the exception "errorClass" equals one of:
| SIGILL |
| SIGTRAP |
And the event "unhandled" is true
And event 0 contains the feature flag "demo_mode" with no variant
And event 0 contains the feature flag "on_send_callback" with no variant
And event 0 does not contain the feature flag "should_not_be_reported_1"
And event 0 does not contain the feature flag "should_not_be_reported_2"
And event 0 does not contain the feature flag "should_not_be_reported_3"
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ org.gradle.jvmargs=-Xmx4096m
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
org.gradle.parallel=true
VERSION_NAME=5.19.1
VERSION_NAME=5.19.2
GROUP=com.bugsnag
POM_SCM_URL=https://github.com/bugsnag/bugsnag-android
POM_SCM_CONNECTION=scm:[email protected]:bugsnag/bugsnag-android.git
Expand Down

0 comments on commit da43423

Please sign in to comment.