Skip to content

Commit 4d56945

Browse files
0xadam-browncodex
andcommitted
fix(sample): Attribute initial Nav3 crashes correctly
Crash only after the first Checkout composition is applied so the navigation transaction and scenario tags are available for attribution. Apply the scenario tag directly to the scope transaction to keep history filtering robust. Refs JAVA-274 Co-Authored-By: OpenAI Codex <noreply@openai.com>
1 parent 253cdc2 commit 4d56945

2 files changed

Lines changed: 10 additions & 7 deletions

File tree

‎sentry-samples/sentry-samples-android/src/main/java/io/sentry/samples/android/navigation/nav3/Nav3MultiActivity.kt‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,8 @@ internal fun MultiActivityRoute(onOpenProducts: () -> Unit) {
270270
* covered by another one.
271271
* @param onCompleteOrder Handles Checkout's "Complete Order" outside this root (e.g., by returning
272272
* a result). When `null`, the confirmation is pushed onto this root's own back stack.
273-
* @param crashOnFirstComposition Crashes while composing the Checkout destination, i.e., while the
274-
* root's first screen is being created, to check that the crash is attributed to that screen.
273+
* @param crashOnFirstComposition Crashes when the Checkout destination's first composition is
274+
* applied, so its navigation transaction and tags can attribute the crash to that screen.
275275
*/
276276
@OptIn(ExperimentalComposeUiApi::class)
277277
@Composable
@@ -417,12 +417,14 @@ internal fun MultiRootNavDisplay(
417417
}
418418
}
419419
entry<Nav3Route.Checkout> { route ->
420-
if (crashOnFirstComposition) {
421-
throw RuntimeException(
422-
"Fatal Nav3 ${scenario.label} crash during first composition"
423-
)
424-
}
425420
TracedNav3Route(route, scenario) {
421+
if (crashOnFirstComposition) {
422+
SideEffect {
423+
throw RuntimeException(
424+
"Fatal Nav3 ${scenario.label} crash after first composition"
425+
)
426+
}
427+
}
426428
Nav3RouteWorkEffect(route, routeWorkOptions)
427429
CheckoutRoute(
428430
route = route,

‎sentry-samples/sentry-samples-android/src/main/java/io/sentry/samples/android/navigation/nav3/Nav3RouteScreens.kt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ private fun tagCurrentNav3Scenario(scenario: Nav3Scenario, activityName: String)
9595
}
9696
Sentry.configureScope { scope ->
9797
scope.withTransaction { transaction ->
98+
transaction?.setTag(NAV3_SCENARIO_TAG, scenario.label)
9899
transaction?.setTag(NAVIGATION_SAMPLE_ACTIVITY_TAG, activityName)
99100
transaction?.setTag(NAVIGATION_SAMPLE_SESSION_TAG, sessionId)
100101
}

0 commit comments

Comments
 (0)