Skip to content

Commit 2f3df97

Browse files
feat(android): Publish Nav3 support (#6233)
Commit adds the wiring needed to publish the sentry-android-navigation3 module, which implements our [phase 1](https://linear.app/getsentry/project/android-nav3-support-28432794ea7d/overview) support for Android's [Nav3 library](https://developer.android.com/guide/navigation/navigation-3). It also removes the `@ApiStatus.Internal` annotations from our public Nav3 APIs, including SentryNavEffect. See the SentryNavEffect KDoc and the sentry-android-navigation3 README for more details. --------- Co-authored-by: Markus Hintersteiner <markus.hintersteiner@sentry.io>
1 parent 2cb909d commit 2f3df97

9 files changed

Lines changed: 33 additions & 17 deletions

File tree

‎.craft.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ targets:
6464
maven:io.sentry:sentry-quartz:
6565
maven:io.sentry:sentry-okhttp:
6666
maven:io.sentry:sentry-android-navigation:
67+
maven:io.sentry:sentry-android-navigation3:
6768
maven:io.sentry:sentry-compose:
6869
maven:io.sentry:sentry-compose-android:
6970
maven:io.sentry:sentry-compose-desktop:

‎CHANGELOG.md‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
### Features
66

7+
- Add support for Android Navigation 3 through the new `sentry-android-navigation3` library ([#6233](https://github.com/getsentry/sentry-java/pull/6233))
8+
- Use `SentryNavEffect` to record navigation transactions, breadcrumbs, screen names, and additional context as your nav back stack changes.
9+
- See the [Navigation for Android docs](https://docs.sentry.io/platforms/android/integrations/navigation/) for additional details.
710
- Report the cellular network technology generation in `device.connection_effective_type`, for example `4g` or `5g` ([#6146](https://github.com/getsentry/sentry-java/pull/6146))
811

912
### Dependencies

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Sentry SDK for Java and Android
2525
| sentry-android-timber | [![Maven Central Version](https://img.shields.io/maven-central/v/io.sentry/sentry-android-timber?style=for-the-badge&logo=sentry&color=green)](https://central.sonatype.com/artifact/io.sentry/sentry-android-timber) | 21 |
2626
| sentry-android-fragment | [![Maven Central Version](https://img.shields.io/maven-central/v/io.sentry/sentry-android-fragment?style=for-the-badge&logo=sentry&color=green)](https://central.sonatype.com/artifact/io.sentry/sentry-android-fragment) | 21 |
2727
| sentry-android-navigation | [![Maven Central Version](https://img.shields.io/maven-central/v/io.sentry/sentry-android-navigation?style=for-the-badge&logo=sentry&color=green)](https://central.sonatype.com/artifact/io.sentry/sentry-android-navigation) | 21 |
28+
| sentry-android-navigation3 | [![Maven Central Version](https://img.shields.io/maven-central/v/io.sentry/sentry-android-navigation3?style=for-the-badge&logo=sentry&color=green)](https://central.sonatype.com/artifact/io.sentry/sentry-android-navigation3) | 23 |
2829
| sentry-android-sqlite | [![Maven Central Version](https://img.shields.io/maven-central/v/io.sentry/sentry-android-sqlite?style=for-the-badge&logo=sentry&color=green)](https://central.sonatype.com/artifact/io.sentry/sentry-android-sqlite) | 21 |
2930
| sentry-android-replay | [![Maven Central Version](https://img.shields.io/maven-central/v/io.sentry/sentry-android-replay?style=for-the-badge&logo=sentry&color=green)](https://central.sonatype.com/artifact/io.sentry/sentry-android-replay) | 26 |
3031
| sentry-compose-android | [![Maven Central Version](https://img.shields.io/maven-central/v/io.sentry/sentry-compose-android?style=for-the-badge&logo=sentry&color=green)](https://central.sonatype.com/artifact/io.sentry/sentry-compose-android) | 21 |
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# sentry-android-navigation3
2+
3+
[Navigation 3](https://developer.android.com/guide/navigation/navigation-3) instrumentation for the Sentry Android SDK.
4+
5+
Use `SentryNavEffect` alongside your `NavDisplay` to record navigation transactions, breadcrumbs, screen names, and back stack context as
6+
users move around your app. Configure the data you want captured via `SentryNavOptions`.
7+
8+
Because Nav3 back stacks can have arbitrary key types, host apps need to provide `SentryNavEffect` with a mapping between their back stack
9+
keys and the data Sentry should display for each (see `BackStackEntryMapper`).
10+
11+
See the [Navigation for Android docs](https://docs.sentry.io/platforms/android/integrations/navigation/) for additional details, including
12+
installation, configuration, and limitations.

‎sentry-android-navigation3/src/main/kotlin/io/sentry/compose/navigation3/BackStackEntryMapper.kt‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import org.jetbrains.annotations.ApiStatus
55

66
/** Info about a given back stack entry, suitable for display in Sentry. */
77
@ApiStatus.Experimental
8-
@ApiStatus.Internal
98
public class SentryBackStackEntry(
109
/**
1110
* A host-app defined name for a given back stack entry.
@@ -104,13 +103,15 @@ public class SentryBackStackEntry(
104103
* - [Map]s
105104
* - [Collection]s
106105
*
107-
* Containers may be nested, but they must bottom out in supported scalar types. Cyclic or deeply
108-
* nested containers will be skipped.
106+
* Containers may be nested, but they must bottom out in supported scalar types.
109107
*
110108
* **Arguments fall back to `toString()` or nothing**
111109
*
112-
* All non-supported argument types are stringified via `toString()`. If [map] throws or returns
113-
* `null`, no arguments are recorded for that back stack entry.
110+
* All non-supported argument types are stringified via `toString()`.
111+
*
112+
* No arguments will be recorded for a back stack entry if [map] throws or returns `null`, or if its
113+
* arguments are cyclic, too deeply nested, or too large. If the SDK drops an entry's arguments, it
114+
* adds a `dropped_by_sentry` field and corresponding reason in the Sentry UI.
114115
*
115116
* **Using kotlinx.serialization**
116117
*
@@ -123,11 +124,11 @@ public class SentryBackStackEntry(
123124
* ```kotlin
124125
* @Serializable
125126
* @SerialName("Home")
126-
* data class Home(userName: String) : NavKey
127+
* data class Home(val userName: String) : NavKey
127128
*
128129
* @Serializable
129130
* @SerialName("ProductDetail")
130-
* data class ProductDetail(userName: String, productId: String, tab: Tab) : NavKey
131+
* data class ProductDetail(val userName: String, val productId: String) : NavKey
131132
*
132133
* ...
133134
*
@@ -138,15 +139,14 @@ public class SentryBackStackEntry(
138139
* name = ProductDetail.serializer().descriptor.serialName,
139140
* // Select a subset of diagnostic arguments when serialization is unsafe
140141
* // or non-performant.
141-
* arguments = mapOf("product_id" to entry.productId, "tab" to entry.tab)
142+
* arguments = mapOf("product_id" to entry.productId)
142143
* )
143144
* ...
144145
* }
145146
* }
146147
* ```
147148
*/
148149
@ApiStatus.Experimental
149-
@ApiStatus.Internal
150150
public fun interface BackStackEntryMapper<T : Any> {
151151
public fun map(backStackEntry: T): SentryBackStackEntry?
152152
}

‎sentry-android-navigation3/src/main/kotlin/io/sentry/compose/navigation3/BackStackObserver.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ private data class BackStackData<T>(
273273
val topEntryNormalized: NormalizedSentryBackStackEntry,
274274
/**
275275
* [NormalizedSentryBackStackEntry]s representing the newest
276-
* [SentryNavOption.maxCapturedBackStackEntries] entries from the host app's back stack.
276+
* [SentryNavOptions.maxCapturedBackStackEntries] entries from the host app's back stack.
277277
*
278278
* Possibly empty.
279279
*/

‎sentry-android-navigation3/src/main/kotlin/io/sentry/compose/navigation3/SentryNavEffect.kt‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,11 @@ import org.jetbrains.annotations.ApiStatus
4444
* By default, the following data is produced every time the top of the provided [backStack]
4545
* changes:
4646
*
47-
* - a new navigation transaction
47+
* - a new navigation transaction (unless another transaction is already active on the current
48+
* scope)
4849
* - a breadcrumb
4950
* - a screen name
50-
* - a record of the current back stack (last 10 entries)
51+
* - a record of the current back stack (last 5 entries)
5152
*
5253
* You can configure the above defaults via [SentryNavOptions]. (Screen names can be disabled via
5354
* [SentryOptions.setEnableScreenTracking].)
@@ -75,7 +76,6 @@ import org.jetbrains.annotations.ApiStatus
7576
* @param options The kinds of navigation info this effect should record.
7677
*/
7778
@ApiStatus.Experimental
78-
@ApiStatus.Internal
7979
@Composable
8080
public fun <T : Any> SentryNavEffect(
8181
backStack: List<T>,

‎sentry-android-navigation3/src/main/kotlin/io/sentry/compose/navigation3/SentryNavOptions.kt‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ private const val DEFAULT_MAX_CAPTURED_BACK_STACK_ENTRIES = 5
1919
* ```
2020
*/
2121
@ApiStatus.Experimental
22-
@ApiStatus.Internal
2322
@Immutable
2423
public class SentryNavOptions
2524
private constructor(
@@ -116,6 +115,5 @@ private constructor(
116115
* ```
117116
*/
118117
@ApiStatus.Experimental
119-
@ApiStatus.Internal
120118
public fun SentryNavOptions(configure: SentryNavOptions.Builder.() -> Unit = {}): SentryNavOptions =
121119
SentryNavOptions.Builder().apply(configure).build()

‎sentry-android-navigation3/src/test/kotlin/io/sentry/compose/navigation3/SentryNavEffectTest.kt‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ package io.sentry.compose.navigation3
33
import android.app.Application
44
import android.content.ComponentName
55
import androidx.activity.ComponentActivity
6-
import androidx.compose.runtime.LaunchedEffect
6+
import androidx.compose.runtime.DisposableEffect
77
import androidx.compose.runtime.mutableIntStateOf
88
import androidx.compose.runtime.mutableStateListOf
99
import androidx.compose.runtime.mutableStateOf
@@ -317,9 +317,10 @@ class SentryNavEffectTest {
317317
)
318318

319319
val currentTop = backStack.last()
320-
LaunchedEffect(currentTop) {
320+
DisposableEffect(currentTop) {
321321
val transaction = fixture.scopes.getSpan() as? SentryTracer
322322
observedTransactionNames += transaction?.name ?: "<none>"
323+
onDispose {}
323324
}
324325
}
325326
composeRule.waitForIdle()

0 commit comments

Comments
 (0)