Skip to content

Commit

Permalink
Rename annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
bidetofevil committed Jan 7, 2025
1 parent c8ea126 commit 8169c3e
Show file tree
Hide file tree
Showing 14 changed files with 83 additions and 72 deletions.
8 changes: 4 additions & 4 deletions embrace-android-api/api/embrace-android-api.api
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -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

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ internal class AutoDataCaptureBehaviorImplTest {
assertTrue(isDiskUsageCaptureEnabled())
assertTrue(isThermalStatusCaptureEnabled())
assertTrue(isUiLoadTracingEnabled())
assertFalse(isUiLoadTracingTraceAll())
assertTrue(isUiLoadTracingTraceAll())
assertTrue(isThermalStatusCaptureEnabled())
assertTrue(isV2StorageEnabled())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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())
Expand All @@ -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)
Expand All @@ -87,8 +92,8 @@ internal class UiLoadTest {
testRule.runTest(
instrumentedConfig = FakeInstrumentedConfig(
enabledFeatures = FakeEnabledFeatureConfig(
uiLoadPerfCapture = true,
uiLoadPerfAutoCapture = false,
uiLoadTracingEnabled = true,
uiLoadTracingTraceAll = false,
bgActivityCapture = true
)
),
Expand Down Expand Up @@ -127,8 +132,8 @@ internal class UiLoadTest {
testRule.runTest(
instrumentedConfig = FakeInstrumentedConfig(
enabledFeatures = FakeEnabledFeatureConfig(
uiLoadPerfCapture = true,
uiLoadPerfAutoCapture = false,
uiLoadTracingEnabled = true,
uiLoadTracingTraceAll = false,
bgActivityCapture = true
)
),
Expand Down Expand Up @@ -167,8 +172,8 @@ internal class UiLoadTest {
testRule.runTest(
instrumentedConfig = FakeInstrumentedConfig(
enabledFeatures = FakeEnabledFeatureConfig(
uiLoadPerfCapture = true,
uiLoadPerfAutoCapture = true,
uiLoadTracingEnabled = true,
uiLoadTracingTraceAll = true,
bgActivityCapture = true
)
),
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ internal class EmbraceActionInterface(
startInBackground: Boolean = false,
createFirstActivity: Boolean = true,
invokeManualEnd: Boolean = false,
activitiesAndActions: List<Pair<ActivityController<*>, () -> Unit>> = listOf(),
activitiesAndActions: List<Pair<ActivityController<*>, () -> Unit>> = listOf(
Robolectric.buildActivity(Activity::class.java) to {},
),
lifecycleEventGap: Long = 100L,
postActionDwell: Long = 20000L,
activityGap: Long = 50L,
Expand Down
Original file line number Diff line number Diff line change
@@ -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()
Original file line number Diff line number Diff line change
@@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}

0 comments on commit 8169c3e

Please sign in to comment.