Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse FeatureFlags when OnSendCallbacks are configured #1589

Merged
merged 1 commit into from
Jan 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## TBD

### 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)

## 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 @@ -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
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 @@ -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"