diff --git a/embrace-android-api/api/embrace-android-api.api b/embrace-android-api/api/embrace-android-api.api index 52a5c24f2..ef44a10eb 100644 --- a/embrace-android-api/api/embrace-android-api.api +++ b/embrace-android-api/api/embrace-android-api.api @@ -24,19 +24,19 @@ public final class io/embrace/android/embracesdk/Severity : java/lang/Enum { public static fun values ()[Lio/embrace/android/embracesdk/Severity; } -public abstract interface annotation class io/embrace/android/embracesdk/annotation/CustomTracedActivity : java/lang/annotation/Annotation { +public abstract interface annotation class io/embrace/android/embracesdk/annotation/CustomLoadTracedActivity : java/lang/annotation/Annotation { } public abstract interface annotation class io/embrace/android/embracesdk/annotation/InternalApi : java/lang/annotation/Annotation { } -public abstract interface annotation class io/embrace/android/embracesdk/annotation/NotTracedActivity : java/lang/annotation/Annotation { +public abstract interface annotation class io/embrace/android/embracesdk/annotation/LoadTracedActivity : java/lang/annotation/Annotation { } -public abstract interface annotation class io/embrace/android/embracesdk/annotation/StartupActivity : java/lang/annotation/Annotation { +public abstract interface annotation class io/embrace/android/embracesdk/annotation/NotTracedActivity : java/lang/annotation/Annotation { } -public abstract interface annotation class io/embrace/android/embracesdk/annotation/TracedActivity : java/lang/annotation/Annotation { +public abstract interface annotation class io/embrace/android/embracesdk/annotation/StartupActivity : java/lang/annotation/Annotation { } public abstract interface class io/embrace/android/embracesdk/internal/api/BreadcrumbApi { diff --git a/embrace-android-api/src/main/kotlin/io/embrace/android/embracesdk/annotation/CustomLoadTracedActivity.kt b/embrace-android-api/src/main/kotlin/io/embrace/android/embracesdk/annotation/CustomLoadTracedActivity.kt new file mode 100644 index 000000000..cff4d99ab --- /dev/null +++ b/embrace-android-api/src/main/kotlin/io/embrace/android/embracesdk/annotation/CustomLoadTracedActivity.kt @@ -0,0 +1,12 @@ +package io.embrace.android.embracesdk.annotation + +/** + * The loading of Activities annotated with this will generate UI Load traces when the SDK is manually notified + * that their loading has finished unless the feature is disabled. + * + * This works similarly to [LoadTracedActivity] except the trace will only be recorded if the appropriate API method + * is called to signal the end of the load. + */ +@Target(AnnotationTarget.CLASS) +@Retention(AnnotationRetention.RUNTIME) +public annotation class CustomLoadTracedActivity diff --git a/embrace-android-api/src/main/kotlin/io/embrace/android/embracesdk/annotation/CustomTracedActivity.kt b/embrace-android-api/src/main/kotlin/io/embrace/android/embracesdk/annotation/CustomTracedActivity.kt deleted file mode 100644 index bec70d168..000000000 --- a/embrace-android-api/src/main/kotlin/io/embrace/android/embracesdk/annotation/CustomTracedActivity.kt +++ /dev/null @@ -1,9 +0,0 @@ -package io.embrace.android.embracesdk.annotation - -/** - * The loading of Activities annotated with this class will generate traces if the feature is enabled, irrespective of - * the configured defaults. - */ -@Target(AnnotationTarget.CLASS) -@Retention(AnnotationRetention.RUNTIME) -public annotation class CustomTracedActivity diff --git a/embrace-android-api/src/main/kotlin/io/embrace/android/embracesdk/annotation/LoadTracedActivity.kt b/embrace-android-api/src/main/kotlin/io/embrace/android/embracesdk/annotation/LoadTracedActivity.kt new file mode 100644 index 000000000..63b458ad7 --- /dev/null +++ b/embrace-android-api/src/main/kotlin/io/embrace/android/embracesdk/annotation/LoadTracedActivity.kt @@ -0,0 +1,8 @@ +package io.embrace.android.embracesdk.annotation + +/** + * The loading of Activities annotated with this will generate UI Load traces unless the feature is disabled. + */ +@Target(AnnotationTarget.CLASS) +@Retention(AnnotationRetention.RUNTIME) +public annotation class LoadTracedActivity diff --git a/embrace-android-api/src/main/kotlin/io/embrace/android/embracesdk/annotation/TracedActivity.kt b/embrace-android-api/src/main/kotlin/io/embrace/android/embracesdk/annotation/TracedActivity.kt deleted file mode 100644 index 21689836b..000000000 --- a/embrace-android-api/src/main/kotlin/io/embrace/android/embracesdk/annotation/TracedActivity.kt +++ /dev/null @@ -1,9 +0,0 @@ -package io.embrace.android.embracesdk.annotation - -/** - * The loading of Activities annotated with this class will generate traces if the feature is enabled, irrespective of - * the configured defaults. - */ -@Target(AnnotationTarget.CLASS) -@Retention(AnnotationRetention.RUNTIME) -public annotation class TracedActivity diff --git a/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/config/behavior/AutoDataCaptureBehaviorImpl.kt b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/config/behavior/AutoDataCaptureBehaviorImpl.kt index 1bae7fcdc..f443f1ab9 100644 --- a/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/config/behavior/AutoDataCaptureBehaviorImpl.kt +++ b/embrace-android-core/src/main/kotlin/io/embrace/android/embracesdk/internal/config/behavior/AutoDataCaptureBehaviorImpl.kt @@ -43,8 +43,8 @@ class AutoDataCaptureBehaviorImpl( override fun isNativeCrashCaptureEnabled(): Boolean = local.isNativeCrashCaptureEnabled() override fun isDiskUsageCaptureEnabled(): Boolean = local.isDiskUsageCaptureEnabled() - override fun isUiLoadTracingEnabled(): Boolean = local.isUiLoadPerfCaptureEnabled() - override fun isUiLoadTracingTraceAll(): Boolean = local.isUiLoadPerfAutoCaptureEnabled() + override fun isUiLoadTracingEnabled(): Boolean = local.isUiLoadTracingEnabled() + override fun isUiLoadTracingTraceAll(): Boolean = local.isUiLoadTracingTraceAll() private val v2StorageImpl by lazy { thresholdCheck.isBehaviorEnabled(remote?.killSwitchConfig?.v2StoragePct) ?: V2_STORAGE_ENABLED_DEFAULT diff --git a/embrace-android-core/src/test/java/io/embrace/android/embracesdk/internal/config/behavior/AutoDataCaptureBehaviorImplTest.kt b/embrace-android-core/src/test/java/io/embrace/android/embracesdk/internal/config/behavior/AutoDataCaptureBehaviorImplTest.kt index 2a46cc33f..a53b41dcd 100644 --- a/embrace-android-core/src/test/java/io/embrace/android/embracesdk/internal/config/behavior/AutoDataCaptureBehaviorImplTest.kt +++ b/embrace-android-core/src/test/java/io/embrace/android/embracesdk/internal/config/behavior/AutoDataCaptureBehaviorImplTest.kt @@ -34,7 +34,7 @@ internal class AutoDataCaptureBehaviorImplTest { assertTrue(isDiskUsageCaptureEnabled()) assertTrue(isThermalStatusCaptureEnabled()) assertTrue(isUiLoadTracingEnabled()) - assertFalse(isUiLoadTracingTraceAll()) + assertTrue(isUiLoadTracingTraceAll()) assertTrue(isThermalStatusCaptureEnabled()) assertTrue(isV2StorageEnabled()) } diff --git a/embrace-android-features/src/main/kotlin/io/embrace/android/embracesdk/internal/capture/activity/UiLoadExt.kt b/embrace-android-features/src/main/kotlin/io/embrace/android/embracesdk/internal/capture/activity/UiLoadExt.kt index 0a36c0261..0b4127a8c 100644 --- a/embrace-android-features/src/main/kotlin/io/embrace/android/embracesdk/internal/capture/activity/UiLoadExt.kt +++ b/embrace-android-features/src/main/kotlin/io/embrace/android/embracesdk/internal/capture/activity/UiLoadExt.kt @@ -4,9 +4,9 @@ import android.app.Activity import android.os.Build.VERSION_CODES import android.os.Bundle import androidx.annotation.RequiresApi -import io.embrace.android.embracesdk.annotation.CustomTracedActivity +import io.embrace.android.embracesdk.annotation.CustomLoadTracedActivity +import io.embrace.android.embracesdk.annotation.LoadTracedActivity import io.embrace.android.embracesdk.annotation.NotTracedActivity -import io.embrace.android.embracesdk.annotation.TracedActivity import io.embrace.android.embracesdk.internal.clock.nanosToMillis import io.embrace.android.embracesdk.internal.session.lifecycle.ActivityLifecycleListener import io.embrace.android.embracesdk.internal.utils.VersionChecker @@ -183,10 +183,10 @@ private class LifecycleEventEmitter( private fun Activity.traceLoad(): Boolean { return (autoTraceEnabled && !javaClass.isAnnotationPresent(NotTracedActivity::class.java)) || isManualEnd() || - javaClass.isAnnotationPresent(TracedActivity::class.java) + javaClass.isAnnotationPresent(LoadTracedActivity::class.java) } - private fun Activity.isManualEnd(): Boolean = javaClass.isAnnotationPresent(CustomTracedActivity::class.java) + private fun Activity.isManualEnd(): Boolean = javaClass.isAnnotationPresent(CustomLoadTracedActivity::class.java) private fun nowMs(): Long = clock.now().nanosToMillis() } diff --git a/embrace-android-payload/src/main/kotlin/io/embrace/android/embracesdk/internal/config/instrumented/schema/EnabledFeatureConfig.kt b/embrace-android-payload/src/main/kotlin/io/embrace/android/embracesdk/internal/config/instrumented/schema/EnabledFeatureConfig.kt index 75d6920ae..5b6c30546 100644 --- a/embrace-android-payload/src/main/kotlin/io/embrace/android/embracesdk/internal/config/instrumented/schema/EnabledFeatureConfig.kt +++ b/embrace-android-payload/src/main/kotlin/io/embrace/android/embracesdk/internal/config/instrumented/schema/EnabledFeatureConfig.kt @@ -149,14 +149,16 @@ interface EnabledFeatureConfig { /** * Gates whether the SDK will capture traces for the performance of the opening of Activities. * - * Will be true if sdk_config.automatic_data_capture.ui_load_perf_info is not "DISABLE" + * Will be true if sdk_config.automatic_data_capture.ui_load_tracing_disabled is not true */ - fun isUiLoadPerfCaptureEnabled(): Boolean = true + fun isUiLoadTracingEnabled(): Boolean = true /** * Gates whether the SDK will default to automatically capture traces for the performance of the opening of all Activities. * - * Will be true sdk_config.automatic_data_capture.ui_load_perf_info equals "ENABLE_ALL" + * Will be true NEITHER of the following is true: + * - sdk_config.automatic_data_capture.ui_load_tracing_disabled + * - sdk_config.automatic_data_capture.ui_load_tracing_selected_only */ - fun isUiLoadPerfAutoCaptureEnabled(): Boolean = false + fun isUiLoadTracingTraceAll(): Boolean = true } diff --git a/embrace-android-sdk/src/integrationTest/kotlin/io/embrace/android/embracesdk/testcases/features/UiLoadTest.kt b/embrace-android-sdk/src/integrationTest/kotlin/io/embrace/android/embracesdk/testcases/features/UiLoadTest.kt index e76204c21..887ad07a9 100644 --- a/embrace-android-sdk/src/integrationTest/kotlin/io/embrace/android/embracesdk/testcases/features/UiLoadTest.kt +++ b/embrace-android-sdk/src/integrationTest/kotlin/io/embrace/android/embracesdk/testcases/features/UiLoadTest.kt @@ -3,9 +3,9 @@ package io.embrace.android.embracesdk.testcases.features import android.app.Activity import android.os.Build import androidx.test.ext.junit.runners.AndroidJUnit4 -import io.embrace.android.embracesdk.annotation.CustomTracedActivity +import io.embrace.android.embracesdk.annotation.CustomLoadTracedActivity +import io.embrace.android.embracesdk.annotation.LoadTracedActivity import io.embrace.android.embracesdk.annotation.NotTracedActivity -import io.embrace.android.embracesdk.annotation.TracedActivity import io.embrace.android.embracesdk.assertions.assertEmbraceSpanData import io.embrace.android.embracesdk.assertions.findSpansByName import io.embrace.android.embracesdk.assertions.findSpansOfType @@ -33,22 +33,31 @@ internal class UiLoadTest { @JvmField val testRule = IntegrationTestRule() + @Config(sdk = [Build.VERSION_CODES.LOLLIPOP]) + @Test + fun `activity open creates a trace by default`() { + testRule.runTest( + instrumentedConfig = FakeInstrumentedConfig( + enabledFeatures = FakeEnabledFeatureConfig(bgActivityCapture = true) + ), + testCaseAction = { + simulateOpeningActivities() + }, + assertAction = { + assertEquals(1, getSingleSessionEnvelope().findSpansOfType(EmbType.Performance.UiLoad).size) + } + ) + } + @Config(sdk = [Build.VERSION_CODES.LOLLIPOP]) @Test fun `activity open does not create a trace if feature flag is disabled`() { testRule.runTest( instrumentedConfig = FakeInstrumentedConfig( - enabledFeatures = FakeEnabledFeatureConfig(uiLoadPerfCapture = false, bgActivityCapture = true) + enabledFeatures = FakeEnabledFeatureConfig(uiLoadTracingEnabled = false, bgActivityCapture = true) ), testCaseAction = { - simulateOpeningActivities( - addStartupActivity = false, - startInBackground = true, - activitiesAndActions = listOf( - Robolectric.buildActivity(Activity1::class.java) to {}, - Robolectric.buildActivity(Activity2::class.java) to {}, - ) - ) + simulateOpeningActivities() }, assertAction = { assertTrue(getSingleSessionEnvelope().findSpansOfType(EmbType.Performance.UiLoad).isEmpty()) @@ -62,17 +71,13 @@ internal class UiLoadTest { testRule.runTest( instrumentedConfig = FakeInstrumentedConfig( enabledFeatures = FakeEnabledFeatureConfig( - uiLoadPerfCapture = true, - uiLoadPerfAutoCapture = true, + uiLoadTracingEnabled = true, + uiLoadTracingTraceAll = true, bgActivityCapture = true ) ), testCaseAction = { - simulateOpeningActivities( - activitiesAndActions = listOf( - Robolectric.buildActivity(Activity::class.java) to {}, - ) - ) + simulateOpeningActivities() }, assertAction = { assertEquals(1, getSingleSessionEnvelope().findSpansOfType(EmbType.Performance.UiLoad).size) @@ -87,8 +92,8 @@ internal class UiLoadTest { testRule.runTest( instrumentedConfig = FakeInstrumentedConfig( enabledFeatures = FakeEnabledFeatureConfig( - uiLoadPerfCapture = true, - uiLoadPerfAutoCapture = false, + uiLoadTracingEnabled = true, + uiLoadTracingTraceAll = false, bgActivityCapture = true ) ), @@ -127,8 +132,8 @@ internal class UiLoadTest { testRule.runTest( instrumentedConfig = FakeInstrumentedConfig( enabledFeatures = FakeEnabledFeatureConfig( - uiLoadPerfCapture = true, - uiLoadPerfAutoCapture = false, + uiLoadTracingEnabled = true, + uiLoadTracingTraceAll = false, bgActivityCapture = true ) ), @@ -167,8 +172,8 @@ internal class UiLoadTest { testRule.runTest( instrumentedConfig = FakeInstrumentedConfig( enabledFeatures = FakeEnabledFeatureConfig( - uiLoadPerfCapture = true, - uiLoadPerfAutoCapture = true, + uiLoadTracingEnabled = true, + uiLoadTracingTraceAll = true, bgActivityCapture = true ) ), @@ -191,7 +196,7 @@ internal class UiLoadTest { var preLaunchTimeMs = 0L testRule.runTest( instrumentedConfig = FakeInstrumentedConfig( - enabledFeatures = FakeEnabledFeatureConfig(uiLoadPerfCapture = true, bgActivityCapture = true) + enabledFeatures = FakeEnabledFeatureConfig(uiLoadTracingEnabled = true, bgActivityCapture = true) ), setupAction = { preLaunchTimeMs = overriddenClock.now() @@ -243,7 +248,7 @@ internal class UiLoadTest { var preLaunchTimeMs = 0L testRule.runTest( instrumentedConfig = FakeInstrumentedConfig( - enabledFeatures = FakeEnabledFeatureConfig(uiLoadPerfCapture = true, bgActivityCapture = true) + enabledFeatures = FakeEnabledFeatureConfig(uiLoadTracingEnabled = true, bgActivityCapture = true) ), setupAction = { preLaunchTimeMs = overriddenClock.now() @@ -298,7 +303,7 @@ internal class UiLoadTest { var preLaunchTimeMs = 0L testRule.runTest( instrumentedConfig = FakeInstrumentedConfig( - enabledFeatures = FakeEnabledFeatureConfig(uiLoadPerfCapture = true, bgActivityCapture = true) + enabledFeatures = FakeEnabledFeatureConfig(uiLoadTracingEnabled = true, bgActivityCapture = true) ), setupAction = { preLaunchTimeMs = overriddenClock.now() @@ -338,16 +343,16 @@ internal class UiLoadTest { } private companion object { - @TracedActivity + @LoadTracedActivity class Activity1 : Activity() - @TracedActivity + @LoadTracedActivity class Activity2 : Activity() @NotTracedActivity class IgnoredActivity : Activity() - @CustomTracedActivity + @CustomLoadTracedActivity class ManualStopActivity : Activity() val ACTIVITY1_NAME = Robolectric.buildActivity(Activity1::class.java).get().localClassName diff --git a/embrace-android-sdk/src/integrationTest/kotlin/io/embrace/android/embracesdk/testframework/actions/EmbraceActionInterface.kt b/embrace-android-sdk/src/integrationTest/kotlin/io/embrace/android/embracesdk/testframework/actions/EmbraceActionInterface.kt index 5fcb56164..fa6efa757 100644 --- a/embrace-android-sdk/src/integrationTest/kotlin/io/embrace/android/embracesdk/testframework/actions/EmbraceActionInterface.kt +++ b/embrace-android-sdk/src/integrationTest/kotlin/io/embrace/android/embracesdk/testframework/actions/EmbraceActionInterface.kt @@ -65,7 +65,9 @@ internal class EmbraceActionInterface( startInBackground: Boolean = false, createFirstActivity: Boolean = true, invokeManualEnd: Boolean = false, - activitiesAndActions: List, () -> Unit>> = listOf(), + activitiesAndActions: List, () -> Unit>> = listOf( + Robolectric.buildActivity(Activity::class.java) to {}, + ), lifecycleEventGap: Long = 100L, postActionDwell: Long = 20000L, activityGap: Long = 50L, diff --git a/embrace-test-fakes/src/main/kotlin/io/embrace/android/embracesdk/fakes/FakeCustomTracedActivity.kt b/embrace-test-fakes/src/main/kotlin/io/embrace/android/embracesdk/fakes/FakeCustomTracedActivity.kt index cddcd2fc1..ad4b10971 100644 --- a/embrace-test-fakes/src/main/kotlin/io/embrace/android/embracesdk/fakes/FakeCustomTracedActivity.kt +++ b/embrace-test-fakes/src/main/kotlin/io/embrace/android/embracesdk/fakes/FakeCustomTracedActivity.kt @@ -1,7 +1,7 @@ package io.embrace.android.embracesdk.fakes import android.app.Activity -import io.embrace.android.embracesdk.annotation.CustomTracedActivity +import io.embrace.android.embracesdk.annotation.CustomLoadTracedActivity -@CustomTracedActivity +@CustomLoadTracedActivity class FakeCustomTracedActivity : Activity() diff --git a/embrace-test-fakes/src/main/kotlin/io/embrace/android/embracesdk/fakes/FakeTracedActivity.kt b/embrace-test-fakes/src/main/kotlin/io/embrace/android/embracesdk/fakes/FakeTracedActivity.kt index 41d63adfe..042fbf98e 100644 --- a/embrace-test-fakes/src/main/kotlin/io/embrace/android/embracesdk/fakes/FakeTracedActivity.kt +++ b/embrace-test-fakes/src/main/kotlin/io/embrace/android/embracesdk/fakes/FakeTracedActivity.kt @@ -1,7 +1,7 @@ package io.embrace.android.embracesdk.fakes import android.app.Activity -import io.embrace.android.embracesdk.annotation.TracedActivity +import io.embrace.android.embracesdk.annotation.LoadTracedActivity -@TracedActivity +@LoadTracedActivity class FakeTracedActivity : Activity() diff --git a/embrace-test-fakes/src/main/kotlin/io/embrace/android/embracesdk/fakes/config/FakeEnabledFeatureConfig.kt b/embrace-test-fakes/src/main/kotlin/io/embrace/android/embracesdk/fakes/config/FakeEnabledFeatureConfig.kt index 385946b1d..a06a69f2c 100644 --- a/embrace-test-fakes/src/main/kotlin/io/embrace/android/embracesdk/fakes/config/FakeEnabledFeatureConfig.kt +++ b/embrace-test-fakes/src/main/kotlin/io/embrace/android/embracesdk/fakes/config/FakeEnabledFeatureConfig.kt @@ -26,8 +26,8 @@ class FakeEnabledFeatureConfig( private val requestContentLengthCapture: Boolean = base.isRequestContentLengthCaptureEnabled(), private val httpUrlConnectionCapture: Boolean = base.isHttpUrlConnectionCaptureEnabled(), private val networkSpanForwarding: Boolean = base.isNetworkSpanForwardingEnabled(), - private val uiLoadPerfCapture: Boolean = base.isUiLoadPerfCaptureEnabled(), - private val uiLoadPerfAutoCapture: Boolean = base.isUiLoadPerfAutoCaptureEnabled(), + private val uiLoadTracingEnabled: Boolean = base.isUiLoadTracingEnabled(), + private val uiLoadTracingTraceAll: Boolean = base.isUiLoadTracingTraceAll(), ) : EnabledFeatureConfig { override fun isUnityAnrCaptureEnabled(): Boolean = unityAnrCapture @@ -52,6 +52,6 @@ class FakeEnabledFeatureConfig( override fun isRequestContentLengthCaptureEnabled(): Boolean = requestContentLengthCapture override fun isHttpUrlConnectionCaptureEnabled(): Boolean = httpUrlConnectionCapture override fun isNetworkSpanForwardingEnabled(): Boolean = networkSpanForwarding - override fun isUiLoadPerfCaptureEnabled(): Boolean = uiLoadPerfCapture - override fun isUiLoadPerfAutoCaptureEnabled(): Boolean = uiLoadPerfAutoCapture + override fun isUiLoadTracingEnabled(): Boolean = uiLoadTracingEnabled + override fun isUiLoadTracingTraceAll(): Boolean = uiLoadTracingTraceAll }