Skip to content

Commit da4dbf8

Browse files
0xadam-browncodex
andauthored
feat(samples): Add Nav3 sample app (JAVA-274) (#6222)
Introduce a sample app for our Sentry Nav3 integration (SentryNavEffect). Key implementation classes are Nav3SetupActivity and Nav3Activity, each of which is closely modeled after the existing Nav2SetupActivity and Nav2Activity that back our Nav2 sample app. Co-Authored-By: Codex <noreply@openai.com>
1 parent 9272cf8 commit da4dbf8

21 files changed

Lines changed: 4685 additions & 1 deletion

‎gradle/libs.versions.toml‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ animalsniffer = "2.0.1"
33
apollo = "2.5.9"
44
androidxLifecycle = "2.2.0"
55
androidxNavigation = "2.9.8"
6+
androidxNavigation3 = "1.1.5"
67
androidxTestCore = "1.7.0"
78
androidxCompose = "1.9.5"
89
asyncProfiler = "4.4"
@@ -109,6 +110,8 @@ androidx-lifecycle-process = { module = "androidx.lifecycle:lifecycle-process",
109110
androidx-navigation-runtime = { module = "androidx.navigation:navigation-runtime", version.ref = "androidxNavigation" }
110111
androidx-navigation-compose = { module = "androidx.navigation:navigation-compose", version.ref = "androidxNavigation" }
111112
androidx-navigation-fragment = { module = "androidx.navigation:navigation-fragment-ktx", version.ref = "androidxNavigation" }
113+
androidx-navigation3-runtime = { module = "androidx.navigation3:navigation3-runtime", version.ref = "androidxNavigation3" }
114+
androidx-navigation3-ui = { module = "androidx.navigation3:navigation3-ui", version.ref = "androidxNavigation3" }
112115
androidx-room-compiler = { module = "androidx.room:room-compiler", version.ref = "room2" }
113116
androidx-room-ktx = { module = "androidx.room:room-ktx", version.ref = "room2" }
114117
androidx-room-runtime = { module = "androidx.room:room-runtime", version.ref = "room2" }

‎sentry-samples/sentry-samples-android/README.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ You can also apply the [Sentry Android Gradle Plugin](https://github.com/getsent
2121

2222
In Android Studio, add `useSagp=` (empty value) to `gradle.properties`, or pass `-PuseSagp` as a Gradle project property.
2323

24+
For LLM-driven verification, use `adb` to inspect and interact with the running emulator. Compose-based screens often expose stable
25+
`Modifier.testTag()` values, which can be used with the UI hierarchy dump to locate controls reliably.
26+
2427
## Build modes
2528

2629
### With or without SAGP

‎sentry-samples/sentry-samples-android/build.gradle.kts‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ dependencies {
187187
implementation(projects.sentryAndroid)
188188
implementation(projects.sentryAndroidFragment)
189189
implementation(projects.sentryAndroidNavigation)
190+
implementation(projects.sentryAndroidNavigation3)
190191
implementation(projects.sentryAndroidSqlite)
191192
implementation(projects.sentryAndroidTimber)
192193
implementation(projects.sentryCompose)
@@ -212,6 +213,8 @@ dependencies {
212213
implementation(libs.androidx.compose.material.icons.extended)
213214
implementation(libs.androidx.navigation.compose)
214215
implementation(libs.androidx.navigation.fragment)
216+
implementation(libs.androidx.navigation3.runtime)
217+
implementation(libs.androidx.navigation3.ui)
215218
implementation(libs.androidx.recyclerview)
216219
implementation(libs.androidx.browser)
217220
implementation(libs.androidx.room3.runtime)

‎sentry-samples/sentry-samples-android/src/main/AndroidManifest.xml‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,17 @@
112112
android:screenOrientation="portrait"
113113
android:theme="@style/AppTheme.Main" />
114114

115+
<activity
116+
android:name=".navigation.nav3.Nav3SetupActivity"
117+
android:exported="false"
118+
android:theme="@style/AppTheme.Main" />
119+
120+
<activity
121+
android:name=".navigation.nav3.Nav3Activity"
122+
android:exported="false"
123+
android:screenOrientation="portrait"
124+
android:theme="@style/AppTheme.Main" />
125+
115126
<activity
116127
android:name=".FrameDataForSpansActivity"
117128
android:exported="false" />

‎sentry-samples/sentry-samples-android/src/main/java/io/sentry/samples/android/MainActivity.kt‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ import io.sentry.compose.SentryTraced
9393
import io.sentry.protocol.Feedback
9494
import io.sentry.protocol.User
9595
import io.sentry.samples.android.memory.MemoryLimiterActivity
96+
import io.sentry.samples.android.navigation.nav3.Nav3SetupActivity
9697
import java.io.File
9798
import java.io.FileOutputStream
9899
import java.io.IOException
@@ -912,6 +913,16 @@ fun IntegrationsScreen() {
912913
}
913914
}
914915
}
916+
item {
917+
SentryTraced("open_nav3_activity") {
918+
OutlinedButton(
919+
onClick = { activity.startActivity(Intent(activity, Nav3SetupActivity::class.java)) },
920+
modifier = Modifier,
921+
) {
922+
Text("Open Nav3 Activity", maxLines = 2, overflow = TextOverflow.Ellipsis)
923+
}
924+
}
925+
}
915926
item {
916927
SentryTraced("open_sample_fragment") {
917928
OutlinedButton(
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Nav2 and Nav3 Samples
2+
3+
## Nav Sample Transaction Tips
4+
5+
When inspecting route-level transactions from `Nav2Activity` or `Nav3Activity`, note that the sample app also enables automatic Activity
6+
tracing by default. That can produce overlapping `ui.load` transactions for the Activity itself, which may make it harder to isolate the
7+
navigation transactions generated by the Nav2 or Nav3 integrations.
8+
9+
If you want the route transactions to be the primary trace surface while testing those sample screens, temporarily disable automatic
10+
Activity tracing in `src/main/AndroidManifest.xml`:
11+
12+
```xml
13+
<meta-data
14+
android:name="io.sentry.traces.activity.enable"
15+
android:value="false" />
16+
```
17+
18+
This is mainly useful for debugging and comparison in the sample app. It is not a general recommendation for production apps.
19+
20+
## Navigation Performance Scenarios
21+
22+
Both navigation samples include an interactive performance scenario for exercising stack mutations and route rendering.
23+
24+
### Nav2
25+
26+
Open Nav2 from the integrations screen, select the `Performance` tab, and use the controls to build a stack or replace the top destination.
27+
The sample also supports automatic recompositions and navigation for sustained stress testing.
28+
29+
### Nav3
30+
31+
Open Nav3 from the integrations screen, select the `Performance` tab, and use the presets or performance controls to run a scenario with the
32+
desired stack depth, workload, integration mode, and argument shape.

‎sentry-samples/sentry-samples-android/src/main/java/io/sentry/samples/android/navigation/nav2/Nav2TransactionHistory.kt‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ internal data class Nav2TraceSpan(
7676
private fun SentryTransaction.toNav2TransactionTrace(dsn: String?): Nav2TransactionTrace {
7777
val trace = contexts.trace
7878
val startTimestamp = startTimestamp
79-
val endTimestamp = timestamp ?: startTimestamp
79+
val endTimestamp =
80+
timestamp ?: spans.mapNotNull { span -> span.timestamp }.maxOrNull() ?: startTimestamp
8081
val durationMillis = ((endTimestamp - startTimestamp) * 1_000.0).coerceAtLeast(0.0)
8182
val rootSpanId = trace?.spanId?.toString()
8283
val traceId = trace?.traceId?.toString().orEmpty()

0 commit comments

Comments
 (0)