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 67a8100a6b..b0980feed8 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. Properties are encoded later, + // when SentryNavEffect reads the arguments, so its own timing includes them. + 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 6c9ccb0e88..c14f4ecf3a 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 b5f432009b..8c0a4899f4 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 @@ -524,15 +524,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( 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 d292324c7e..28ac663db3 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