From 5cc75658d1786c6837fe61e58624836e670f2e0d Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Mon, 30 Nov 2026 11:56:12 +0100 Subject: [PATCH 1/3] feat(nav3): Use the SerialNameAndProperties mapper in the Android samples The Nav3 samples now record each route's properties with the built-in SerialNameAndProperties mapper instead of pairing SerialName with hand-written arguments. Each property's @SerialName is the Nav2 sample's argument name, and a null campaign is still left out, so both samples send the same data. The performance scenario gains a SerialNameAndProperties mapper mode alongside Custom and SerialName. Co-Authored-By: Claude Opus 5.5 --- .../android/navigation/nav3/Nav3Activity.kt | 15 +++++++-- .../navigation/nav3/Nav3MultiActivity.kt | 2 +- .../nav3/Nav3PerformanceControls.kt | 23 ++++++++++---- .../android/navigation/nav3/Nav3Routes.kt | 31 ++++++++++++------- 4 files changed, 50 insertions(+), 21 deletions(-) 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..b0980feed84 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 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..8c0a4899f48 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 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 From b57f1c14f81498fdc90fe83c65f8640156d8030d Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Fri, 4 Dec 2026 11:48:52 +0100 Subject: [PATCH 2/3] fix(samples): Cap the Nav3 sample's captured back stack entries at 25 SentryNavOptions now treats maxCapturedBackStackEntries values above 25 as 25. The sample showed and labelled its own value, so presets and steppers that went up to 100 would have shown a capture count the SDK no longer uses. Stop the steppers and launch extras at 25, and lower the presets above it. Also correct the Performance tab's comment on timing the built-in mapper, which now encodes the route's properties when it maps the route. Refs JAVA-787 Co-Authored-By: Claude Opus 5.5 --- .../common/NavigationSampleConfig.kt | 3 +++ .../common/NavigationSetupScreen.kt | 6 ++++-- .../android/navigation/nav3/Nav3Activity.kt | 4 ++-- .../nav3/Nav3PerformanceControls.kt | 21 +++++++++++-------- .../navigation/nav3/Nav3SampleConfig.kt | 7 +++++-- 5 files changed, 26 insertions(+), 15 deletions(-) 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 b0980feed84..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 @@ -245,8 +245,8 @@ private fun Nav3SampleApp( if (!isPerformanceScenario) { 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. + // 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 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 8c0a4899f48..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 @@ -608,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, @@ -619,7 +620,7 @@ internal enum class Nav3PerformancePreset( HEAVY( "Heavy", 50, - 50, + MAX_CAPTURED_BACK_STACK_ENTRIES, Nav3PerformanceIntegrationMode.FULL_STACK, Nav3PerformanceExtractorMode.NORMAL, Nav3PerformanceArgumentMode.NESTED, @@ -627,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, @@ -635,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, @@ -643,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, @@ -651,7 +652,7 @@ internal enum class Nav3PerformancePreset( DISABLED_CONTROL( "Disabled control", 30, - 30, + MAX_CAPTURED_BACK_STACK_ENTRIES, Nav3PerformanceIntegrationMode.DISABLED, Nav3PerformanceExtractorMode.NORMAL, Nav3PerformanceArgumentMode.EMPTY, @@ -819,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/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" From be0855f3e90bea3df22b8d30cde091634b7065c6 Mon Sep 17 00:00:00 2001 From: Adam Brown Date: Fri, 4 Dec 2026 13:37:24 +0100 Subject: [PATCH 3/3] changelog Co-Authored-By: Claude Opus 5.5 --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) 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))