From d8e8e8a74197177c47dcc16dc833ba18689f8e11 Mon Sep 17 00:00:00 2001 From: fractalwrench Date: Wed, 21 Apr 2021 09:59:05 +0100 Subject: [PATCH] fix: add projectPackages to event payload --- CHANGELOG.md | 3 +++ .../src/main/java/com/bugsnag/android/EventInternal.kt | 7 +++++++ .../test/java/com/bugsnag/android/BugsnagTestUtils.java | 2 ++ .../test/java/com/bugsnag/android/ImmutableConfigTest.kt | 2 +- .../src/test/resources/event_redaction.json | 3 +++ .../src/test/resources/event_serialization_0.json | 3 +++ .../src/test/resources/event_serialization_1.json | 3 +++ .../src/test/resources/event_serialization_2.json | 3 +++ .../src/test/resources/event_serialization_3.json | 3 +++ .../src/test/resources/event_serialization_4.json | 3 +++ .../src/test/resources/event_serialization_5.json | 3 +++ .../src/test/resources/event_serialization_6.json | 3 +++ features/smoke_tests/handled.feature | 6 ++++++ features/smoke_tests/unhandled.feature | 2 ++ 14 files changed, 45 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2a7cc1e53e..ecdc59f0d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ ### Bug fixes +* Add projectPackages field to error payloads + [#1226](https://github.com/bugsnag/bugsnag-android/pull/1226) + * Fix deserialization bug in persisted NDK errors [#1220](https://github.com/bugsnag/bugsnag-android/pull/1220) diff --git a/bugsnag-android-core/src/main/java/com/bugsnag/android/EventInternal.kt b/bugsnag-android-core/src/main/java/com/bugsnag/android/EventInternal.kt index ef038961c5..06d23aa63f 100644 --- a/bugsnag-android-core/src/main/java/com/bugsnag/android/EventInternal.kt +++ b/bugsnag-android-core/src/main/java/com/bugsnag/android/EventInternal.kt @@ -11,6 +11,7 @@ internal class EventInternal @JvmOverloads internal constructor( val metadata: Metadata = data.copy() private val discardClasses: Set = config.discardClasses.toSet() + private val projectPackages = config.projectPackages @JvmField internal var session: Session? = null @@ -84,6 +85,12 @@ internal class EventInternal @JvmOverloads internal constructor( errors.forEach { writer.value(it) } writer.endArray() + // Write project packages + writer.name("projectPackages") + writer.beginArray() + projectPackages.forEach { writer.value(it) } + writer.endArray() + // Write user info writer.name("user").value(_user) diff --git a/bugsnag-android-core/src/test/java/com/bugsnag/android/BugsnagTestUtils.java b/bugsnag-android-core/src/test/java/com/bugsnag/android/BugsnagTestUtils.java index d12226bb3c..3f4714fe8c 100644 --- a/bugsnag-android-core/src/test/java/com/bugsnag/android/BugsnagTestUtils.java +++ b/bugsnag-android-core/src/test/java/com/bugsnag/android/BugsnagTestUtils.java @@ -5,6 +5,7 @@ import java.io.File; import java.io.IOException; import java.nio.file.Files; +import java.util.Collections; import java.util.Date; import java.util.HashMap; @@ -21,6 +22,7 @@ static Configuration generateConfiguration() { Configuration configuration = new Configuration("5d1ec5bd39a74caa1267142706a7fb21"); configuration.setDelivery(generateDelivery()); configuration.setLogger(NoopLogger.INSTANCE); + configuration.setProjectPackages(Collections.singleton("com.example.foo")); try { File dir = Files.createTempDirectory("test").toFile(); configuration.setPersistenceDirectory(dir); diff --git a/bugsnag-android-core/src/test/java/com/bugsnag/android/ImmutableConfigTest.kt b/bugsnag-android-core/src/test/java/com/bugsnag/android/ImmutableConfigTest.kt index b521bc8124..7729df8c29 100644 --- a/bugsnag-android-core/src/test/java/com/bugsnag/android/ImmutableConfigTest.kt +++ b/bugsnag-android-core/src/test/java/com/bugsnag/android/ImmutableConfigTest.kt @@ -59,7 +59,7 @@ internal class ImmutableConfigTest { // release stages assertTrue(discardClasses.isEmpty()) assertNull(enabledReleaseStages) - assertTrue(projectPackages.isEmpty()) + assertEquals(setOf("com.example.foo"), projectPackages) assertEquals(seed.releaseStage, releaseStage) // identifiers diff --git a/bugsnag-android-core/src/test/resources/event_redaction.json b/bugsnag-android-core/src/test/resources/event_redaction.json index f96578b407..a037f1a006 100644 --- a/bugsnag-android-core/src/test/resources/event_redaction.json +++ b/bugsnag-android-core/src/test/resources/event_redaction.json @@ -17,6 +17,9 @@ }, "unhandled": false, "exceptions": [], + "projectPackages":[ + "com.example.foo" + ], "user": {}, "app": { "type": "android", diff --git a/bugsnag-android-core/src/test/resources/event_serialization_0.json b/bugsnag-android-core/src/test/resources/event_serialization_0.json index 1cf6c4a655..f1fabdbf03 100644 --- a/bugsnag-android-core/src/test/resources/event_serialization_0.json +++ b/bugsnag-android-core/src/test/resources/event_serialization_0.json @@ -7,6 +7,9 @@ }, "unhandled": false, "exceptions": [], + "projectPackages":[ + "com.example.foo" + ], "user": {}, "app": { "type": "android", diff --git a/bugsnag-android-core/src/test/resources/event_serialization_1.json b/bugsnag-android-core/src/test/resources/event_serialization_1.json index d781896999..cd4e6c2b07 100644 --- a/bugsnag-android-core/src/test/resources/event_serialization_1.json +++ b/bugsnag-android-core/src/test/resources/event_serialization_1.json @@ -8,6 +8,9 @@ }, "unhandled": false, "exceptions": [], + "projectPackages":[ + "com.example.foo" + ], "user": {}, "app": { "type": "android", diff --git a/bugsnag-android-core/src/test/resources/event_serialization_2.json b/bugsnag-android-core/src/test/resources/event_serialization_2.json index 2b0b736501..7543d67f17 100644 --- a/bugsnag-android-core/src/test/resources/event_serialization_2.json +++ b/bugsnag-android-core/src/test/resources/event_serialization_2.json @@ -7,6 +7,9 @@ }, "unhandled": false, "exceptions": [], + "projectPackages":[ + "com.example.foo" + ], "user": {}, "app": { "type": "android", diff --git a/bugsnag-android-core/src/test/resources/event_serialization_3.json b/bugsnag-android-core/src/test/resources/event_serialization_3.json index 6bd4d4fdc9..194abe9127 100644 --- a/bugsnag-android-core/src/test/resources/event_serialization_3.json +++ b/bugsnag-android-core/src/test/resources/event_serialization_3.json @@ -7,6 +7,9 @@ }, "unhandled": false, "exceptions": [], + "projectPackages":[ + "com.example.foo" + ], "user": {}, "app": { "type": "android", diff --git a/bugsnag-android-core/src/test/resources/event_serialization_4.json b/bugsnag-android-core/src/test/resources/event_serialization_4.json index 11c93963aa..dfe36cd998 100644 --- a/bugsnag-android-core/src/test/resources/event_serialization_4.json +++ b/bugsnag-android-core/src/test/resources/event_serialization_4.json @@ -7,6 +7,9 @@ }, "unhandled": false, "exceptions": [], + "projectPackages":[ + "com.example.foo" + ], "user": {}, "app": { "type": "android", diff --git a/bugsnag-android-core/src/test/resources/event_serialization_5.json b/bugsnag-android-core/src/test/resources/event_serialization_5.json index f442492b49..3b016294e0 100644 --- a/bugsnag-android-core/src/test/resources/event_serialization_5.json +++ b/bugsnag-android-core/src/test/resources/event_serialization_5.json @@ -7,6 +7,9 @@ }, "unhandled": false, "exceptions": [], + "projectPackages":[ + "com.example.foo" + ], "user": {}, "app": { "type": "android", diff --git a/bugsnag-android-core/src/test/resources/event_serialization_6.json b/bugsnag-android-core/src/test/resources/event_serialization_6.json index 560f3061a8..df1e4cc12c 100644 --- a/bugsnag-android-core/src/test/resources/event_serialization_6.json +++ b/bugsnag-android-core/src/test/resources/event_serialization_6.json @@ -24,6 +24,9 @@ "stacktrace": [] } ], + "projectPackages":[ + "com.example.foo" + ], "user": { "name": "Jamie" }, diff --git a/features/smoke_tests/handled.feature b/features/smoke_tests/handled.feature index 983c9912e0..dd314a940a 100644 --- a/features/smoke_tests/handled.feature +++ b/features/smoke_tests/handled.feature @@ -22,6 +22,8 @@ Scenario: Notify caught Java exception with default configuration # R8 minification alters the lineNumber, see the mapping file/source code for the original value And the event "exceptions.0.stacktrace.0.lineNumber" equals 8 And the event "exceptions.0.stacktrace.0.inProject" is true + And the error payload field "events.0.projectPackages" is a non-empty array + And the event "projectPackages.0" equals "com.bugsnag.android.mazerunner" And the thread with name "main" contains the error reporting flag And the "method" of stack frame 0 equals "com.bugsnag.android.mazerunner.scenarios.HandledJavaSmokeScenario.startScenario" @@ -116,6 +118,8 @@ Scenario: Notify Kotlin exception with overwritten configuration And the event "severity" equals "error" And the event "severityReason.type" equals "userCallbackSetSeverity" And the event "severityReason.unhandledOverridden" is false + And the error payload field "events.0.projectPackages" is a non-empty array + And the event "projectPackages.0" equals "com.bugsnag.android.mazerunner" # Stacktrace validation And the error payload field "events.0.exceptions.0.stacktrace" is a non-empty array @@ -171,6 +175,8 @@ Scenario: Handled C functionality And the event "severity" equals "error" And the event "severityReason.type" equals "userCallbackSetSeverity" And the event "severityReason.unhandledOverridden" is false + And the error payload field "events.0.projectPackages" is a non-empty array + And the event "projectPackages.0" equals "com.bugsnag.android.mazerunner" # App data And the event "app.buildUUID" is not null diff --git a/features/smoke_tests/unhandled.feature b/features/smoke_tests/unhandled.feature index 83eec3449d..9dd18c0753 100644 --- a/features/smoke_tests/unhandled.feature +++ b/features/smoke_tests/unhandled.feature @@ -15,6 +15,8 @@ Scenario: Unhandled Java Exception with loaded configuration And the event "severity" equals "error" And the event "severityReason.type" equals "unhandledException" And the event "severityReason.unhandledOverridden" is false + And the error payload field "events.0.projectPackages" is a non-empty array + And the event "projectPackages.0" equals "com.bugsnag.android.mazerunner" # Stacktrace validation And the error payload field "events.0.exceptions.0.stacktrace" is a non-empty array