Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -236,9 +238,12 @@ internal fun SnapshotStateList<Nav3Route>.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
Expand All @@ -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<String, Any?>
get() = emptyMap()
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand All @@ -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

Expand Down
Loading