From 7f7657949a8ab4df413bc367ca03185983d617e0 Mon Sep 17 00:00:00 2001 From: fractalwrench Date: Mon, 22 Feb 2021 13:59:00 +0000 Subject: [PATCH] feat: add launchDurationMillis config option --- CHANGELOG.md | 7 +++ .../android/ManifestConfigLoaderTest.kt | 8 ++- .../com/bugsnag/android/ConfigInternal.kt | 2 +- .../com/bugsnag/android/Configuration.java | 50 ++++++++++++++----- .../com/bugsnag/android/EventFilenameInfo.kt | 2 +- .../java/com/bugsnag/android/EventStore.java | 2 +- .../com/bugsnag/android/ImmutableConfig.kt | 4 +- .../bugsnag/android/ManifestConfigLoader.kt | 11 +++- .../android/ConfigurationFacadeTest.java | 9 +++- .../bugsnag/android/ConfigurationTest.java | 15 +++++- .../bugsnag/android/ImmutableConfigTest.kt | 8 ++- .../com/bugsnag/android/ConfigSerializer.java | 2 +- 12 files changed, 94 insertions(+), 26 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 02bfeabaa5..3e2a5326ea 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Changelog +## TBD + +### Enhancements + +* Add launchDurationMillis config option + [#1157](https://github.com/bugsnag/bugsnag-android/pull/1157) + ## 5.7.0 (2021-02-18) ### Enhancements diff --git a/bugsnag-android-core/src/androidTest/java/com/bugsnag/android/ManifestConfigLoaderTest.kt b/bugsnag-android-core/src/androidTest/java/com/bugsnag/android/ManifestConfigLoaderTest.kt index 7f4adc6854..f0ade4ddc6 100644 --- a/bugsnag-android-core/src/androidTest/java/com/bugsnag/android/ManifestConfigLoaderTest.kt +++ b/bugsnag-android-core/src/androidTest/java/com/bugsnag/android/ManifestConfigLoaderTest.kt @@ -48,7 +48,9 @@ class ManifestConfigLoaderTest { assertEquals(maxBreadcrumbs, 25) assertEquals(maxPersistedEvents, 32) assertEquals(maxPersistedSessions, 128) + @Suppress("DEPRECATION") assertEquals(launchCrashThresholdMs, 5000) + assertEquals(launchDurationMillis, 5000) assertEquals("android", appType) } } @@ -83,7 +85,7 @@ class ManifestConfigLoaderTest { putInt("com.bugsnag.android.MAX_BREADCRUMBS", 50) putInt("com.bugsnag.android.MAX_PERSISTED_EVENTS", 52) putInt("com.bugsnag.android.MAX_PERSISTED_SESSIONS", 64) - putInt("com.bugsnag.android.LAUNCH_CRASH_THRESHOLD_MS", 7000) + putInt("com.bugsnag.android.LAUNCH_DURATION_MILLIS", 7000) putString("com.bugsnag.android.APP_TYPE", "react-native") putString("com.bugsnag.android.CODE_BUNDLE_ID", "123") } @@ -116,7 +118,9 @@ class ManifestConfigLoaderTest { assertEquals(maxBreadcrumbs, 50) assertEquals(maxPersistedEvents, 52) assertEquals(maxPersistedSessions, 64) + @Suppress("DEPRECATION") assertEquals(launchCrashThresholdMs, 7000) + assertEquals(launchDurationMillis, 7000) assertEquals("react-native", appType) } } @@ -126,12 +130,14 @@ class ManifestConfigLoaderTest { val data = Bundle().apply { putString("com.bugsnag.android.API_KEY", "5d1ec5bd39a74caa1267142706a7fb21") putBoolean("com.bugsnag.android.ENABLE_EXCEPTION_HANDLER", false) + putInt("com.bugsnag.android.LAUNCH_CRASH_THRESHOLD_MS", 8000) } val config = configLoader.load(data, null) with(config) { assertEquals("5d1ec5bd39a74caa1267142706a7fb21", apiKey) + assertEquals(8000, launchDurationMillis) } } } diff --git a/bugsnag-android-core/src/main/java/com/bugsnag/android/ConfigInternal.kt b/bugsnag-android-core/src/main/java/com/bugsnag/android/ConfigInternal.kt index 8b9fc0c8c0..ff301dc671 100644 --- a/bugsnag-android-core/src/main/java/com/bugsnag/android/ConfigInternal.kt +++ b/bugsnag-android-core/src/main/java/com/bugsnag/android/ConfigInternal.kt @@ -19,7 +19,7 @@ internal class ConfigInternal(var apiKey: String) : CallbackAware, MetadataAware var sendThreads: ThreadSendPolicy = ThreadSendPolicy.ALWAYS var persistUser: Boolean = false - var launchCrashThresholdMs: Long = DEFAULT_LAUNCH_CRASH_THRESHOLD_MS + var launchDurationMillis: Long = DEFAULT_LAUNCH_CRASH_THRESHOLD_MS var autoTrackSessions: Boolean = true var enabledErrorTypes: ErrorTypes = ErrorTypes() diff --git a/bugsnag-android-core/src/main/java/com/bugsnag/android/Configuration.java b/bugsnag-android-core/src/main/java/com/bugsnag/android/Configuration.java index e9da33af12..95c0fc8b71 100644 --- a/bugsnag-android-core/src/main/java/com/bugsnag/android/Configuration.java +++ b/bugsnag-android-core/src/main/java/com/bugsnag/android/Configuration.java @@ -228,31 +228,55 @@ public void setPersistenceDirectory(@Nullable File directory) { impl.setPersistenceDirectory(directory); } + /** + * Deprecated. Use {@link #getLaunchDurationMillis()} instead. + */ + @Deprecated + public long getLaunchCrashThresholdMs() { + getLogger().w("The launchCrashThresholdMs configuration option is deprecated " + + "and will be removed in a future release. Please use " + + "launchDurationMillis instead."); + return getLaunchDurationMillis(); + } + + /** + * Deprecated. Use {@link #setLaunchDurationMillis(long)} ()} instead. + */ + @Deprecated + public void setLaunchCrashThresholdMs(long launchCrashThresholdMs) { + getLogger().w("The launchCrashThresholdMs configuration option is deprecated " + + "and will be removed in a future release. Please use " + + "launchDurationMillis instead."); + setLaunchDurationMillis(launchCrashThresholdMs); + } + /** * Sets the threshold in milliseconds for an uncaught error to be considered as a crash on - * launch. If a crash is detected on launch, Bugsnag will attempt to send the event - * synchronously. + * launch. If a crash is detected on launch, Bugsnag will attempt to send the most recent + * event synchronously. * - * By default, this value is set at 5,000ms. Setting the value to 0 will disable this behaviour. + * By default, this value is set at 5,000ms. Setting the value to 0 will count all crashes + * as launch crashes until markLaunchCompleted() is called. */ - public long getLaunchCrashThresholdMs() { - return impl.getLaunchCrashThresholdMs(); + public long getLaunchDurationMillis() { + return impl.getLaunchDurationMillis(); } /** * Sets the threshold in milliseconds for an uncaught error to be considered as a crash on - * launch. If a crash is detected on launch, Bugsnag will attempt to send the event - * synchronously. + * launch. If a crash is detected on launch, Bugsnag will attempt to send the most recent + * event synchronously. * - * By default, this value is set at 5,000ms. Setting the value to 0 will disable this behaviour. + * By default, this value is set at 5,000ms. Setting the value to 0 will count all crashes + * as launch crashes until markLaunchCompleted() is called. */ - public void setLaunchCrashThresholdMs(long launchCrashThresholdMs) { - if (launchCrashThresholdMs > MIN_LAUNCH_CRASH_THRESHOLD_MS) { - impl.setLaunchCrashThresholdMs(launchCrashThresholdMs); + public void setLaunchDurationMillis(long launchDurationMillis) { + if (launchDurationMillis >= MIN_LAUNCH_CRASH_THRESHOLD_MS) { + impl.setLaunchDurationMillis(launchDurationMillis); } else { getLogger().e(String.format(Locale.US, "Invalid configuration value detected. " - + "Option launchCrashThresholdMs should be a positive long value." - + "Supplied value is %d", launchCrashThresholdMs)); + + "Option launchDurationMillis should be a positive long value." + + "Supplied value is %d", launchDurationMillis)); } } diff --git a/bugsnag-android-core/src/main/java/com/bugsnag/android/EventFilenameInfo.kt b/bugsnag-android-core/src/main/java/com/bugsnag/android/EventFilenameInfo.kt index a4405b4aba..e2d8d6edde 100644 --- a/bugsnag-android-core/src/main/java/com/bugsnag/android/EventFilenameInfo.kt +++ b/bugsnag-android-core/src/main/java/com/bugsnag/android/EventFilenameInfo.kt @@ -157,7 +157,7 @@ internal data class EventFilenameInfo( } private fun isStartupCrash(durationMs: Long, config: ImmutableConfig): Boolean { - return durationMs < config.launchCrashThresholdMs + return durationMs < config.launchDurationMillis } } } diff --git a/bugsnag-android-core/src/main/java/com/bugsnag/android/EventStore.java b/bugsnag-android-core/src/main/java/com/bugsnag/android/EventStore.java index 564ab8167a..32b5324332 100644 --- a/bugsnag-android-core/src/main/java/com/bugsnag/android/EventStore.java +++ b/bugsnag-android-core/src/main/java/com/bugsnag/android/EventStore.java @@ -61,7 +61,7 @@ public int compare(File lhs, File rhs) { } void flushOnLaunch() { - if (config.getLaunchCrashThresholdMs() != 0) { + if (config.getLaunchDurationMillis() != 0) { List storedFiles = findStoredFiles(); final List crashReports = findLaunchCrashReports(storedFiles); diff --git a/bugsnag-android-core/src/main/java/com/bugsnag/android/ImmutableConfig.kt b/bugsnag-android-core/src/main/java/com/bugsnag/android/ImmutableConfig.kt index 8ccfa6a55d..b961ee5d1f 100644 --- a/bugsnag-android-core/src/main/java/com/bugsnag/android/ImmutableConfig.kt +++ b/bugsnag-android-core/src/main/java/com/bugsnag/android/ImmutableConfig.kt @@ -23,7 +23,7 @@ internal data class ImmutableConfig( val delivery: Delivery, val endpoints: EndpointConfiguration, val persistUser: Boolean, - val launchCrashThresholdMs: Long, + val launchDurationMillis: Long, val logger: Logger, val maxBreadcrumbs: Int, val maxPersistedEvents: Int, @@ -79,7 +79,7 @@ internal fun convertToImmutableConfig( delivery = config.delivery, endpoints = config.endpoints, persistUser = config.persistUser, - launchCrashThresholdMs = config.launchCrashThresholdMs, + launchDurationMillis = config.launchDurationMillis, logger = config.logger!!, maxBreadcrumbs = config.maxBreadcrumbs, maxPersistedEvents = config.maxPersistedEvents, diff --git a/bugsnag-android-core/src/main/java/com/bugsnag/android/ManifestConfigLoader.kt b/bugsnag-android-core/src/main/java/com/bugsnag/android/ManifestConfigLoader.kt index 59c8a1b918..94b63019b3 100644 --- a/bugsnag-android-core/src/main/java/com/bugsnag/android/ManifestConfigLoader.kt +++ b/bugsnag-android-core/src/main/java/com/bugsnag/android/ManifestConfigLoader.kt @@ -38,6 +38,7 @@ internal class ManifestConfigLoader { private const val MAX_PERSISTED_EVENTS = "$BUGSNAG_NS.MAX_PERSISTED_EVENTS" private const val MAX_PERSISTED_SESSIONS = "$BUGSNAG_NS.MAX_PERSISTED_SESSIONS" private const val LAUNCH_CRASH_THRESHOLD_MS = "$BUGSNAG_NS.LAUNCH_CRASH_THRESHOLD_MS" + private const val LAUNCH_DURATION_MILLIS = "$BUGSNAG_NS.LAUNCH_DURATION_MILLIS" private const val APP_TYPE = "$BUGSNAG_NS.APP_TYPE" } @@ -75,8 +76,14 @@ internal class ManifestConfigLoader { maxBreadcrumbs = data.getInt(MAX_BREADCRUMBS, maxBreadcrumbs) maxPersistedEvents = data.getInt(MAX_PERSISTED_EVENTS, maxPersistedEvents) maxPersistedSessions = data.getInt(MAX_PERSISTED_SESSIONS, maxPersistedSessions) - launchCrashThresholdMs = - data.getInt(LAUNCH_CRASH_THRESHOLD_MS, launchCrashThresholdMs.toInt()).toLong() + launchDurationMillis = data.getInt( + LAUNCH_CRASH_THRESHOLD_MS, + launchDurationMillis.toInt() + ).toLong() + launchDurationMillis = data.getInt( + LAUNCH_DURATION_MILLIS, + launchDurationMillis.toInt() + ).toLong() } } return config diff --git a/bugsnag-android-core/src/test/java/com/bugsnag/android/ConfigurationFacadeTest.java b/bugsnag-android-core/src/test/java/com/bugsnag/android/ConfigurationFacadeTest.java index 03d8f199c3..6f6952ad54 100644 --- a/bugsnag-android-core/src/test/java/com/bugsnag/android/ConfigurationFacadeTest.java +++ b/bugsnag-android-core/src/test/java/com/bugsnag/android/ConfigurationFacadeTest.java @@ -91,10 +91,17 @@ public void persistUserValid() { assertTrue(config.impl.getPersistUser()); } + @SuppressWarnings("deprecation") @Test public void launchCrashThresholdMsValid() { config.setLaunchCrashThresholdMs(123456); - assertEquals(123456, config.impl.getLaunchCrashThresholdMs()); + assertEquals(123456, config.impl.getLaunchDurationMillis()); + } + + @Test + public void launchDurationMillisValid() { + config.setLaunchDurationMillis(123456); + assertEquals(123456, config.impl.getLaunchDurationMillis()); } @Test diff --git a/bugsnag-android-core/src/test/java/com/bugsnag/android/ConfigurationTest.java b/bugsnag-android-core/src/test/java/com/bugsnag/android/ConfigurationTest.java index c4442ef0d5..760266f875 100644 --- a/bugsnag-android-core/src/test/java/com/bugsnag/android/ConfigurationTest.java +++ b/bugsnag-android-core/src/test/java/com/bugsnag/android/ConfigurationTest.java @@ -94,8 +94,9 @@ private ImmutableConfig createConfigWithReleaseStages(Configuration config, return BugsnagTestUtils.convert(config); } + @SuppressWarnings("deprecation") @Test - public void testLaunchThreshold() { + public void testLaunchThresholdDeprecated() { assertEquals(5000L, config.getLaunchCrashThresholdMs()); config.setLaunchCrashThresholdMs(-5); @@ -106,6 +107,18 @@ public void testLaunchThreshold() { assertEquals(expected, config.getLaunchCrashThresholdMs()); } + @Test + public void testLaunchThreshold() { + assertEquals(5000L, config.getLaunchDurationMillis()); + + config.setLaunchDurationMillis(-5); + assertEquals(5000, config.getLaunchDurationMillis()); + + int expected = 1500; + config.setLaunchDurationMillis(expected); + assertEquals(expected, config.getLaunchDurationMillis()); + } + @Test public void testAutoTrackSessions() { assertTrue(config.getAutoTrackSessions()); 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 ca0a2c8187..19a5d5ac97 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 @@ -71,7 +71,9 @@ internal class ImmutableConfigTest { assertEquals(seed.endpoints, endpoints) // behaviour - assertEquals(seed.launchCrashThresholdMs, launchCrashThresholdMs) + @Suppress("DEPRECATION") // tests deprecated option is set via launchDurationMillis + assertEquals(seed.launchCrashThresholdMs, launchDurationMillis) + assertEquals(seed.launchDurationMillis, launchDurationMillis) assertEquals(NoopLogger, seed.logger) assertEquals(seed.maxBreadcrumbs, maxBreadcrumbs) assertEquals(seed.maxPersistedEvents, maxPersistedEvents) @@ -100,7 +102,7 @@ internal class ImmutableConfigTest { val endpoints = EndpointConfiguration("http://example.com:1234", "http://example.com:1235") seed.endpoints = endpoints - seed.launchCrashThresholdMs = 7000 + seed.launchDurationMillis = 7000 seed.maxBreadcrumbs = 37 seed.maxPersistedEvents = 55 seed.maxPersistedSessions = 103 @@ -136,6 +138,8 @@ internal class ImmutableConfigTest { assertEquals(endpoints1.sessions, endpoints.sessions) // behaviour + assertEquals(7000, seed.launchDurationMillis) + @Suppress("DEPRECATION") // should be same as launchDurationMillis assertEquals(7000, seed.launchCrashThresholdMs) assertEquals(NoopLogger, seed.logger) assertEquals(37, seed.maxBreadcrumbs) diff --git a/bugsnag-plugin-react-native/src/main/java/com/bugsnag/android/ConfigSerializer.java b/bugsnag-plugin-react-native/src/main/java/com/bugsnag/android/ConfigSerializer.java index f17347367d..1b36bbdf9b 100644 --- a/bugsnag-plugin-react-native/src/main/java/com/bugsnag/android/ConfigSerializer.java +++ b/bugsnag-plugin-react-native/src/main/java/com/bugsnag/android/ConfigSerializer.java @@ -25,7 +25,7 @@ public void serialize(Map map, ImmutableConfig config) { map.put("versionCode", config.getVersionCode()); map.put("type", config.getAppType()); map.put("persistUser", config.getPersistUser()); - map.put("launchCrashThresholdMs", (int) config.getLaunchCrashThresholdMs()); + map.put("launchCrashThresholdMs", (int) config.getLaunchDurationMillis()); map.put("maxBreadcrumbs", config.getMaxBreadcrumbs()); map.put("enabledBreadcrumbTypes", serializeBreadrumbTypes(config)); map.put("enabledErrorTypes", serializeErrorTypes(config));