diff --git a/CHANGELOG.md b/CHANGELOG.md index bba6668cecf..63a69b64915 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,10 @@ - Nav3: Record why a back stack entry is `/unknown` via an `unknown_entry_reason` next to it in the Sentry UI ([#6801](https://github.com/getsentry/sentry-java/pull/6801)) - A `BackStackEntryMapper` that throws now records `"unknown_entry_reason": "mapping_failed"` instead of `"dropped_by_sentry": "mapping_failed"` in the entry's arguments. +### Behavioral Changes + +- Nav3: `SentryNavOptions.maxCapturedBackStackEntries` is now capped at 25, and larger values are treated as 25 ([#6707](https://github.com/getsentry/sentry-java/pull/6707)) + ### Fixes - Session Replay: Mask Compose images loaded with Coil 3.1+ `AsyncImage` when `maskAllImages` is enabled ([#6759](https://github.com/getsentry/sentry-java/pull/6759)) diff --git a/sentry-android-integration-tests/sentry-samples-android/src/main/java/io/sentry/samples/android/navigation/common/NavigationSampleConfig.kt b/sentry-android-integration-tests/sentry-samples-android/src/main/java/io/sentry/samples/android/navigation/common/NavigationSampleConfig.kt index 61bde68b2a3..e7e88d228b2 100644 --- a/sentry-android-integration-tests/sentry-samples-android/src/main/java/io/sentry/samples/android/navigation/common/NavigationSampleConfig.kt +++ b/sentry-android-integration-tests/sentry-samples-android/src/main/java/io/sentry/samples/android/navigation/common/NavigationSampleConfig.kt @@ -2,6 +2,9 @@ package io.sentry.samples.android.navigation.common import io.sentry.Sentry +/** The most back stack entries `SentryNavOptions` captures; it treats larger values as this. */ +internal const val MAX_CAPTURED_BACK_STACK_ENTRIES = 25 + /** Configuration shared by nav sample apps. */ internal data class NavigationSampleConfig( val enableNavigationTransactions: Boolean = true, diff --git a/sentry-android-integration-tests/sentry-samples-android/src/main/java/io/sentry/samples/android/navigation/common/NavigationSetupScreen.kt b/sentry-android-integration-tests/sentry-samples-android/src/main/java/io/sentry/samples/android/navigation/common/NavigationSetupScreen.kt index bef3414ab4f..869b44ecccb 100644 --- a/sentry-android-integration-tests/sentry-samples-android/src/main/java/io/sentry/samples/android/navigation/common/NavigationSetupScreen.kt +++ b/sentry-android-integration-tests/sentry-samples-android/src/main/java/io/sentry/samples/android/navigation/common/NavigationSetupScreen.kt @@ -123,6 +123,7 @@ internal fun NavigationSetupScreen( NavigationSetupCounterRow( label = "Max captured back stack entries", value = configuration.maxCapturedBackStackEntries, + maxValue = MAX_CAPTURED_BACK_STACK_ENTRIES, enabled = configuration.captureBackStack, ) { onConfigurationChanged(configuration.copy(maxCapturedBackStackEntries = it)) @@ -247,6 +248,7 @@ private fun NavigationSetupCheckboxRow( private fun NavigationSetupCounterRow( label: String, value: Int, + maxValue: Int, enabled: Boolean, onValueChange: (Int) -> Unit, ) { @@ -317,8 +319,8 @@ private fun NavigationSetupCounterRow( NavigationSetupCounterButton( label = "+", - enabled = enabled, - onClick = { onValueChange(value + 1) }, + enabled = enabled && value < maxValue, + onClick = { onValueChange((value + 1).coerceAtMost(maxValue)) }, color = sentryPurple, ) } diff --git a/sentry-android-integration-tests/sentry-samples-android/src/main/java/io/sentry/samples/android/navigation/nav3/Nav3Activity.kt b/sentry-android-integration-tests/sentry-samples-android/src/main/java/io/sentry/samples/android/navigation/nav3/Nav3Activity.kt index 67a8100a6ba..b974c03d39c 100644 --- a/sentry-android-integration-tests/sentry-samples-android/src/main/java/io/sentry/samples/android/navigation/nav3/Nav3Activity.kt +++ b/sentry-android-integration-tests/sentry-samples-android/src/main/java/io/sentry/samples/android/navigation/nav3/Nav3Activity.kt @@ -243,10 +243,19 @@ private fun Nav3SampleApp( integrationMode.includeArguments, ) { if (!isPerformanceScenario) { - // Names each route after its serial name, and adds the arguments the route selects. + BackStackEntryMapper.SerialNameAndProperties + } else if (performanceMapperMode == Nav3PerformanceMapperMode.SERIAL_NAME_AND_PROPERTIES) { + // Times the duration of each call to the built-in mapper, which includes encoding the + // route's properties. + val mapper = + if (integrationMode.includeArguments) { + BackStackEntryMapper.SerialNameAndProperties + } else { + BackStackEntryMapper.SerialName + } BackStackEntryMapper { route -> - BackStackEntryMapper.SerialName.map(route)?.let { entry -> - SentryBackStackEntry(name = entry.name, arguments = route.arguments) + performanceState.recordNameExtraction("Nav3Stress.serialNameAndPropertiesMapping") { + mapper.map(route) } } } else if (performanceMapperMode == Nav3PerformanceMapperMode.SERIAL_NAME) { diff --git a/sentry-android-integration-tests/sentry-samples-android/src/main/java/io/sentry/samples/android/navigation/nav3/Nav3MultiActivity.kt b/sentry-android-integration-tests/sentry-samples-android/src/main/java/io/sentry/samples/android/navigation/nav3/Nav3MultiActivity.kt index 6c9ccb0e886..c14f4ecf3ab 100644 --- a/sentry-android-integration-tests/sentry-samples-android/src/main/java/io/sentry/samples/android/navigation/nav3/Nav3MultiActivity.kt +++ b/sentry-android-integration-tests/sentry-samples-android/src/main/java/io/sentry/samples/android/navigation/nav3/Nav3MultiActivity.kt @@ -307,7 +307,7 @@ internal fun MultiRootNavDisplay( // Keep this before the NavDisplay below: TracedNav3Route's resume tagging relies on it. SentryNavEffect( backStack = backStack, - backStackEntryMapper = BackStackEntryMapper.SerialName, + backStackEntryMapper = BackStackEntryMapper.SerialNameAndProperties, options = options, ) val onBack: () -> Unit = { diff --git a/sentry-android-integration-tests/sentry-samples-android/src/main/java/io/sentry/samples/android/navigation/nav3/Nav3PerformanceControls.kt b/sentry-android-integration-tests/sentry-samples-android/src/main/java/io/sentry/samples/android/navigation/nav3/Nav3PerformanceControls.kt index b5f432009bd..50ec071351c 100644 --- a/sentry-android-integration-tests/sentry-samples-android/src/main/java/io/sentry/samples/android/navigation/nav3/Nav3PerformanceControls.kt +++ b/sentry-android-integration-tests/sentry-samples-android/src/main/java/io/sentry/samples/android/navigation/nav3/Nav3PerformanceControls.kt @@ -37,6 +37,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.platform.testTag import androidx.compose.ui.text.font.FontWeight import androidx.compose.ui.unit.dp +import io.sentry.samples.android.navigation.common.MAX_CAPTURED_BACK_STACK_ENTRIES import java.util.Locale import kotlin.math.ceil import kotlinx.coroutines.delay @@ -524,15 +525,26 @@ internal enum class Nav3PerformanceArgumentMode(val label: String) { LARGE("Large"), } -/** - * Selects the performance scenario's mapper. - * - * [CUSTOM] provides synthetic arguments and separate extractor timings. [SERIAL_NAME] uses the - * built-in mapper, which extracts names only; each of its calls is timed as name extraction. - */ +/** Selects the performance scenario's mapper. */ internal enum class Nav3PerformanceMapperMode(val label: String) { + + /** Provides synthetic arguments and separate extractor timings. */ CUSTOM("Custom"), + + /** + * Uses the built-in mapper, which extracts names only. + * + * Each of its calls is timed as a name extraction. + */ SERIAL_NAME("SerialName"), + + /** + * Uses the built-in mapper that also records each route's properties. + * + * It records the route's real properties rather than the synthetic arguments that the "Argument + * shape" control selects, so that control is disabled in this mode. + */ + SERIAL_NAME_AND_PROPERTIES("SerialNameAndProperties"), } internal enum class Nav3PerformanceIntegrationMode( @@ -597,10 +609,10 @@ internal enum class Nav3PerformancePreset( Nav3PerformanceExtractorMode.NORMAL, Nav3PerformanceArgumentMode.FLAT, ), - CAPTURE_100_OF_100( - "Capture 100 of 100", - 100, + CAPTURE_25_OF_100( + "Capture 25 of 100", 100, + MAX_CAPTURED_BACK_STACK_ENTRIES, Nav3PerformanceIntegrationMode.FULL_STACK, Nav3PerformanceExtractorMode.NORMAL, Nav3PerformanceArgumentMode.FLAT, @@ -608,7 +620,7 @@ internal enum class Nav3PerformancePreset( HEAVY( "Heavy", 50, - 50, + MAX_CAPTURED_BACK_STACK_ENTRIES, Nav3PerformanceIntegrationMode.FULL_STACK, Nav3PerformanceExtractorMode.NORMAL, Nav3PerformanceArgumentMode.NESTED, @@ -616,7 +628,7 @@ internal enum class Nav3PerformancePreset( SUPER_HEAVY( "Super heavy", 100, - 100, + MAX_CAPTURED_BACK_STACK_ENTRIES, Nav3PerformanceIntegrationMode.FULL_STACK, Nav3PerformanceExtractorMode.HEAVY, Nav3PerformanceArgumentMode.LARGE, @@ -624,7 +636,7 @@ internal enum class Nav3PerformancePreset( NO_ARGUMENTS( "No arguments", 100, - 100, + MAX_CAPTURED_BACK_STACK_ENTRIES, Nav3PerformanceIntegrationMode.FULL_STACK_WITHOUT_ARGUMENTS, Nav3PerformanceExtractorMode.HEAVY, Nav3PerformanceArgumentMode.LARGE, @@ -632,7 +644,7 @@ internal enum class Nav3PerformancePreset( TOP_ONLY( "Top only", 30, - 30, + MAX_CAPTURED_BACK_STACK_ENTRIES, Nav3PerformanceIntegrationMode.TOP_ONLY, Nav3PerformanceExtractorMode.NORMAL, Nav3PerformanceArgumentMode.FLAT, @@ -640,7 +652,7 @@ internal enum class Nav3PerformancePreset( DISABLED_CONTROL( "Disabled control", 30, - 30, + MAX_CAPTURED_BACK_STACK_ENTRIES, Nav3PerformanceIntegrationMode.DISABLED, Nav3PerformanceExtractorMode.NORMAL, Nav3PerformanceArgumentMode.EMPTY, @@ -808,7 +820,9 @@ internal fun Nav3PerformancePanel( }, onIncrement = { controls.onMaxCapturedBackStackEntriesChange( - (controls.maxCapturedBackStackEntries + 1).coerceAtMost(100), + (controls.maxCapturedBackStackEntries + 1).coerceAtMost( + MAX_CAPTURED_BACK_STACK_ENTRIES, + ), ) }, ) diff --git a/sentry-android-integration-tests/sentry-samples-android/src/main/java/io/sentry/samples/android/navigation/nav3/Nav3Routes.kt b/sentry-android-integration-tests/sentry-samples-android/src/main/java/io/sentry/samples/android/navigation/nav3/Nav3Routes.kt index d292324c7e2..28ac663db38 100644 --- a/sentry-android-integration-tests/sentry-samples-android/src/main/java/io/sentry/samples/android/navigation/nav3/Nav3Routes.kt +++ b/sentry-android-integration-tests/sentry-samples-android/src/main/java/io/sentry/samples/android/navigation/nav3/Nav3Routes.kt @@ -11,6 +11,8 @@ import io.sentry.samples.android.navigation.common.RouteNames import io.sentry.samples.android.navigation.common.RouteSpec import io.sentry.samples.android.navigation.common.RouteSpecs import io.sentry.samples.android.navigation.common.displayRoute +import kotlinx.serialization.EncodeDefault +import kotlinx.serialization.ExperimentalSerializationApi import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -236,9 +238,12 @@ internal fun SnapshotStateList.replacePerformanceTop(generation: Int) } /** - * The sample's serializable back stack keys. Each `@SerialName` supplies its Sentry route name, - * using the Nav2 sample's [RouteNames] for shared routes. Only constructor properties are - * serialized. + * The sample's serializable back stack keys, which `BackStackEntryMapper.SerialNameAndProperties` + * maps: a route's `@SerialName` supplies its Sentry name, and each property's `@SerialName` its + * argument name. + * + * Both use the Nav2 sample's [RouteNames] and [NavArgs], so the two samples send the same data. + * Only constructor properties are serialized. * * [routeName] and [arguments] mirror the sample's mapper output so screens, tags, and transaction * checks can read them without invoking the mapper. Mapping stays in `SentryNavEffect`, keeping @@ -252,8 +257,8 @@ internal sealed interface Nav3Route { val routeName: String /** - * The route's arguments as the sample's mapper records them: each property under the Nav2 - * sample's [NavArgs] name, with a `null` campaign left out, as in the Nav2 sample. + * The route's arguments as `SerialNameAndProperties` records them: each property under its + * `@SerialName`, the Nav2 sample's [NavArgs] name, with a `null` campaign left out. */ val arguments: Map get() = emptyMap() @@ -335,11 +340,15 @@ internal sealed interface Nav3Route { get() = RouteNames.PRODUCT_LIST } + @OptIn(ExperimentalSerializationApi::class) @Serializable @SerialName(RouteNames.PRODUCT_DETAIL) data class ProductDetail( - val productId: String, - val source: String, + @SerialName(NavArgs.PRODUCT_ID) val productId: String, + @SerialName(NavArgs.SOURCE) val source: String, + // Omitted from the arguments when null, like the Nav2 sample. + @EncodeDefault(EncodeDefault.Mode.NEVER) + @SerialName(NavArgs.CAMPAIGN) val campaign: String? = null, ) : Nav3Route { override val routeName: String @@ -358,7 +367,7 @@ internal sealed interface Nav3Route { @Serializable @SerialName(RouteNames.CHECKOUT) - data class Checkout(val productId: String) : Nav3Route { + data class Checkout(@SerialName(NavArgs.PRODUCT_ID) val productId: String) : Nav3Route { override val routeName: String get() = RouteNames.CHECKOUT @@ -371,7 +380,7 @@ internal sealed interface Nav3Route { @Serializable @SerialName(RouteNames.CONFIRMATION) - data class Confirmation(val orderId: String) : Nav3Route { + data class Confirmation(@SerialName(NavArgs.ORDER_ID) val orderId: String) : Nav3Route { override val routeName: String get() = RouteNames.CONFIRMATION @@ -384,7 +393,7 @@ internal sealed interface Nav3Route { @Serializable @SerialName(RouteNames.PROMO_DIALOG) - data class PromoDialog(val promoId: String) : Nav3Route { + data class PromoDialog(@SerialName(NavArgs.PROMO_ID) val promoId: String) : Nav3Route { override val routeName: String get() = RouteNames.PROMO_DIALOG @@ -397,7 +406,7 @@ internal sealed interface Nav3Route { @Serializable @SerialName(RouteNames.SHARE_SHEET) - data class ShareSheet(val productId: String) : Nav3Route { + data class ShareSheet(@SerialName(NavArgs.PRODUCT_ID) val productId: String) : Nav3Route { override val routeName: String get() = RouteNames.SHARE_SHEET diff --git a/sentry-android-integration-tests/sentry-samples-android/src/main/java/io/sentry/samples/android/navigation/nav3/Nav3SampleConfig.kt b/sentry-android-integration-tests/sentry-samples-android/src/main/java/io/sentry/samples/android/navigation/nav3/Nav3SampleConfig.kt index 88d752218cc..f31c06905fa 100644 --- a/sentry-android-integration-tests/sentry-samples-android/src/main/java/io/sentry/samples/android/navigation/nav3/Nav3SampleConfig.kt +++ b/sentry-android-integration-tests/sentry-samples-android/src/main/java/io/sentry/samples/android/navigation/nav3/Nav3SampleConfig.kt @@ -3,6 +3,7 @@ package io.sentry.samples.android.navigation.nav3 import android.content.Context import android.content.Intent import android.os.Bundle +import io.sentry.samples.android.navigation.common.MAX_CAPTURED_BACK_STACK_ENTRIES import io.sentry.samples.android.navigation.common.NavigationSampleConfig import io.sentry.samples.android.navigation.common.NavigationSampleConfigSnapshot @@ -37,7 +38,8 @@ internal fun Intent.nav3SampleConfig(): NavigationSampleConfig = getBooleanExtra(EXTRA_ENABLE_USER_INTERACTION_BREADCRUMBS, false), captureBackStack = getBooleanExtra(EXTRA_CAPTURE_BACK_STACK, true), maxCapturedBackStackEntries = - getIntExtra(EXTRA_MAX_CAPTURED_BACK_STACK_ENTRIES, 10).coerceAtLeast(1), + getIntExtra(EXTRA_MAX_CAPTURED_BACK_STACK_ENTRIES, 10) + .coerceIn(1, MAX_CAPTURED_BACK_STACK_ENTRIES), ) internal fun Context.nav3LaunchIntent( @@ -103,7 +105,8 @@ internal fun Bundle.nav3SampleConfiguration(): NavigationSampleConfig = enableUserInteractionBreadcrumbs = getBoolean(STATE_ENABLE_USER_INTERACTION_BREADCRUMBS, false), captureBackStack = getBoolean(STATE_CAPTURE_BACK_STACK, true), maxCapturedBackStackEntries = - getInt(STATE_MAX_CAPTURED_BACK_STACK_ENTRIES, 10).coerceAtLeast(1), + getInt(STATE_MAX_CAPTURED_BACK_STACK_ENTRIES, 10) + .coerceIn(1, MAX_CAPTURED_BACK_STACK_ENTRIES), ) private const val EXTRA_PREFIX = "io.sentry.samples.android.navigation.nav3"