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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
### Features

- Nav3: Add `BackStackEntryMapper.SerialName`, a convenience mapper that names back stack entries after their [serial names](https://kotlinlang.org/api/kotlinx.serialization/kotlinx-serialization-core/kotlinx.serialization.descriptors/-serial-descriptor/serial-name.html) ([#6703](https://github.com/getsentry/sentry-java/pull/6703))
- Nav3: Add `BackStackEntryMapper.SerialNameAndProperties`, which is like `SerialName` except that it also records the properties of each back stack entry as arguments ([#6706](https://github.com/getsentry/sentry-java/pull/6706))

### Improvements

Expand Down
3 changes: 2 additions & 1 deletion sentry-android-navigation3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ This module requires Nav3. It doesn't declare its own dependencies on Compose, l
your Nav3 dependency brings in.

Because Nav3 back stacks can have arbitrary key types, host apps need to provide `SentryNavEffect` with a mapping between their back stack
keys and the data Sentry should display for each (see `BackStackEntryMapper` and the built-in `SerialName` mapper).
keys and the data Sentry should display for each (see `BackStackEntryMapper` and the built-in `SerialName` and `SerialNameAndProperties`
mappers).

See the [Navigation for Android docs](https://docs.sentry.io/platforms/android/integrations/navigation/) for additional details, including
configuration, supported setups, and limitations.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public abstract interface class io/sentry/compose/navigation3/BackStackEntryMapp

public final class io/sentry/compose/navigation3/BackStackEntryMapper$Companion {
public final fun getSerialName ()Lio/sentry/compose/navigation3/BackStackEntryMapper;
public final fun getSerialNameAndProperties ()Lio/sentry/compose/navigation3/BackStackEntryMapper;
}

public final class io/sentry/compose/navigation3/BuildConfig {
Expand Down
5 changes: 3 additions & 2 deletions sentry-android-navigation3/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@

##---------------Begin: proguard configuration for kotlinx.serialization ----------

# Serial names survive R8 minification because Kotlin's serialization compiler plugin fixes them at compile time. Our built-in mapper
# fallback for private `@Serializable` objects relies on members preserved by kotlinx.serialization's own consumer rules.
# Serial names, including the property names `SerialNameAndProperties` records as argument keys, survive R8 minification because Kotlin's
# serialization compiler plugin fixes them at compile time. Our built-in mappers' fallback for private `@Serializable` objects relies on
# members preserved by kotlinx.serialization's own consumer rules.

# We don't ship rules for `@Serializable` classes with named companion objects. kotlinx.serialization's rules cover them but only from
# 1.10.0 on. A generic rule set that fixes older versions exists, but we don't apply it because it would keep `InnerClasses` and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,19 @@ import org.jetbrains.annotations.ApiStatus
/**
* Maps a back stack entry to a displayable name and optional diagnostic arguments.
*
* See [SerialName] for an out-of-the-box mapper, or else provide your own.
* See [SerialName] and [SerialNameAndProperties] for out-of-the-box mappers, or else provide your
* own.
*
* **Privacy / PII**
*
* Host apps are responsible for filtering their own arguments, including removing any sensitive or
* personal information. Only return names and arguments that are known to be safe or have been
* pre-scrubbed.
*
* Neither `sendDefaultPii` nor the `dataCollection` options change what any mapper returns.
* `SerialNameAndProperties` filters only a limited set of secrets; see its documentation for
* details.
*
* **Performance**
*
* Mappers are invoked synchronously from [SentryNavEffect] on the same apply thread that runs the
Expand Down Expand Up @@ -93,7 +98,7 @@ import org.jetbrains.annotations.ApiStatus
* )
*
* // Consider falling back to a built-in mapper for the rest.
* else -> BackStackEntryMapper.SerialName.map(entry)
* else -> BackStackEntryMapper.SerialNameAndProperties.map(entry)
* }
* }
* ```
Expand Down Expand Up @@ -125,7 +130,8 @@ public fun interface BackStackEntryMapper<in T : Any> {
* ```
*
* this mapper returns `"ProductDetailScreen"` for `ProductDetail(productId = "zyx987")` but
* omits the destination's properties (`productId`).
* omits the destination's properties (`productId`). (To return arguments too, see
* [SerialNameAndProperties].)
*
* **Name == SerialDescriptor.serialName**
*
Expand All @@ -142,7 +148,8 @@ public fun interface BackStackEntryMapper<in T : Any> {
* particular:
*
* - All constants of an enum share the enum class's serial name, regardless of any
* `@SerialName` on the constants.
* `@SerialName` on the constants. (A constant's `@SerialName` only changes how
* [SerialNameAndProperties] records it as an argument.)
*
* - Classes that share a custom serializer (`@Serializable(with = ...)`) share its descriptor's
* serial name, regardless of any `@SerialName` on the classes.
Expand All @@ -158,12 +165,69 @@ public fun interface BackStackEntryMapper<in T : Any> {
* Sentry displays `null` entries as "/unknown" with an `unknown_entry_reason`. With SDK
* debugging enabled, the first unnamed entry of each class also logs a warning.
*
* See the
* [Troubleshooting Guide](https://docs.sentry.io/platforms/android/integrations/navigation/#troubleshooting-kotlinxserialization-mappers)
* for more details.
* See the discussion of
* [Unknown Destination Names](https://docs.sentry.io/platforms/android/integrations/navigation/#unknown-destination-names)
* in the Sentry Android Navigation docs for more details.
*/
public val SerialName: BackStackEntryMapper<Any>
get() = BuiltInBackStackEntryMappers.serialName

/**
* Like [SerialName], but also returns the properties that each back stack entry's serializer
* encodes, as Sentry arguments.
*
* For instance, given:
* ```
* @Serializable
* @SerialName("ProductDetailScreen")
* data class ProductDetail(val userId: String, val productId: String) : NavKey
* ```
*
* this mapper returns `"ProductDetailScreen"` for `ProductDetail(userId = "123abc", productId =
* "zyx987")`, along with these arguments:
* ```json
* {
* "userId": "123abc",
* "productId": "zyx987"
* }
* ```
*
* Entry names follow the rules for [SerialName]. Entries that can't be named are recorded as
* "/unknown" with an `unknown_entry_reason`. They're returned without arguments, since their
* inability to be named means they have no usable serializer. The argument limits described in
* [BackStackEntryMapper] apply.
*
* **Privacy / PII**
*
* This mapper returns every property that each back stack entry's serializer encodes, which may
* include private data and PII. Properties the serializer doesn't encode (e.g., `@Transient`
* ones) aren't returned. Apart from the limited filtering of secrets described below,
* properties are sent as-is.
*
* If an entry contains data that shouldn't be sent to Sentry, either filter that property out
* of this mapper's arguments, or use a custom [BackStackEntryMapper] that special-cases the
* entry and falls back to this mapper (or [SerialName]) for the rest. See
* [Choosing Which Arguments to Send](https://docs.sentry.io/platforms/android/integrations/navigation/#choosing-which-arguments-to-send)
* for examples.
*
* **Limited filtering of secrets**
*
* If a property's
* [serial name](https://kotlinlang.org/api/kotlinx.serialization/kotlinx-serialization-core/kotlinx.serialization.descriptors/-serial-descriptor/serial-name.html)
* or map key contains a term from
* [Sentry's sensitive denylist](https://develop.sentry.dev/sdk/foundations/client/data-collection/#sensitive-denylist)
* (ignoring case), then its value will be replaced with `"[Filtered]"`. See
* [Choosing Which Arguments to Send](https://docs.sentry.io/platforms/android/integrations/navigation/#choosing-which-arguments-to-send)
* for more details.
*
* **Argument encoding failures**
*
* Argument encoding failures preserve the entry's name and replace its arguments with a drop
* reason, e.g., `{"dropped_by_sentry": "encoding_failed"}`. With `debug` enabled, the first
* failure of each kind for each entry type also logs a warning.
*/
public val SerialNameAndProperties: BackStackEntryMapper<Any>
get() = BuiltInBackStackEntryMappers.serialNameAndProperties
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ internal object BuiltInBackStackEntryMappers {
* A built-in [BackStackEntryMapper] for apps that use kotlinx.serialization and only need to
* track the serial name of each of their back stack entries (and not each entry's properties).
*
* Falls back to [UnavailableBackStackEntryMapper] if the kotlinx mapper can't be created.
* Falls back to [UnavailableBackStackEntryMapper] if the underlying kotlinx mapper can't be
* created.
*
* See [BackStackEntryMapper.SerialName] for more details.
*/
Expand All @@ -34,6 +35,21 @@ internal object BuiltInBackStackEntryMappers {
create(logger) { KotlinxBackStackEntryMapper(logger = logger) }
}

/**
* Like [serialName], but also returns the properties of each back stack entry as Sentry
* arguments.
*
* Falls back to [UnavailableBackStackEntryMapper] if the underlying kotlinx mapper can't be
* created.
*
* See [BackStackEntryMapper.SerialNameAndProperties] for more details.
*/
val serialNameAndProperties: BackStackEntryMapper<Any> =
// Deferred for the same reason as serialName.
DeferredBackStackEntryMapper {
create(logger) { KotlinxBackStackEntryMapper(includeProperties = true, logger = logger) }
}

/**
* Returns the mapper created by [newKotlinxMapper], or an [UnavailableBackStackEntryMapper] if
* the mapper can't be linked or initialized.
Expand Down
Loading
Loading