Skip to content

Commit

Permalink
feat: add launchDurationMillis config option
Browse files Browse the repository at this point in the history
  • Loading branch information
fractalwrench committed Feb 22, 2021
1 parent 324571e commit 7f76579
Show file tree
Hide file tree
Showing 12 changed files with 94 additions and 26 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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")
}
Expand Down Expand Up @@ -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)
}
}
Expand All @@ -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)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ internal data class EventFilenameInfo(
}

private fun isStartupCrash(durationMs: Long, config: ImmutableConfig): Boolean {
return durationMs < config.launchCrashThresholdMs
return durationMs < config.launchDurationMillis
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public int compare(File lhs, File rhs) {
}

void flushOnLaunch() {
if (config.getLaunchCrashThresholdMs() != 0) {
if (config.getLaunchDurationMillis() != 0) {
List<File> storedFiles = findStoredFiles();
final List<File> crashReports = findLaunchCrashReports(storedFiles);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void serialize(Map<String, Object> 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));
Expand Down

0 comments on commit 7f76579

Please sign in to comment.