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 kotlinx.serialization serial names ([#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))

### Fixes

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 @@ -6,7 +6,8 @@ Use `SentryNavEffect` alongside your `NavDisplay` to record navigation transacti
users move around your app. Configure the data you want captured via `SentryNavOptions`.

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
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,17 @@ public class SentryBackStackEntry(
/**
* Maps a back stack entry to a displayable name and optional diagnostic arguments.
*
* If you use kotlinx.serialization, see [SerialName] for convenient, out-of-the-box mappers.
* Otherwise, provide your own implementation. (Note: Custom implementations can always fall back to
* `SerialName` for any entries that don't have to be special-cased.)
* If you use kotlinx.serialization, see [SerialName] and [SerialNameAndProperties] for convenient,
* out-of-the-box mappers. Otherwise, provide your own implementation. (Note: Custom implementations
* can always fall back to `SerialName` or `SerialNameAndProperties` for any entries that don't have
* to be special-cased.)
*
* **Privacy / PII**
*
* Custom mappers are responsible for filtering their own arguments.
* Built-in mappers that capture entry properties apply limited sensitive-data filtering before
* recording arguments; see [SerialNameAndProperties] for the filtering rules. Custom mappers are
* responsible for filtering their own arguments; Sentry does not apply its built-in sensitive-data
* filtering to arguments they supply themselves.
*
* Only return names and arguments that are known to be safe or have been pre-scrubbed. All
* arguments remain subject to size and structural limits.
Expand Down Expand Up @@ -144,6 +148,8 @@ public fun interface BackStackEntryMapper<in T : Any> {
* would return `"ProductDetail"` as the destination's name, but would ***not*** return the
* destination's properties (`userId` and `productId`).
*
* To return both entry names and properties, see [SerialNameAndProperties].
*
* **Name == SerialDescriptor.serialName**
*
* This mapper names each back stack entry after the entry's
Expand Down Expand Up @@ -177,8 +183,8 @@ public fun interface BackStackEntryMapper<in T : Any> {
*
* Entries share a Sentry name whenever their serializers share a serial name. In particular:
*
* - All constants of an enum are named after the enum. A `@SerialName` on a constant does not
* change the destination name.
* - All constants of an enum are named after the enum. A `@SerialName` on a constant only
* changes how [SerialNameAndProperties] records the constant as an argument.
*
* - Classes that use the same custom serializer (`@Serializable(with = ...)`) are named after
* that serializer's descriptor, which ignores a `@SerialName` on the class.
Expand All @@ -189,5 +195,72 @@ public fun interface BackStackEntryMapper<in T : Any> {
@get:ApiStatus.Experimental
public val SerialName: BackStackEntryMapper<Any>
get() = BuiltInBackStackEntryMappers.serialName

/**
* Like [SerialName], but also returns the properties of each back stack entry as Sentry
* arguments.
*
* For instance, given:
* ```
* @Serializable
* @SerialName("ProductDetail")
* data class ProductDetail(
* val userId: String,
* val productId: String
* ) : NavKey
* ```
*
* when navigating to `ProductDetail(userId = "123abc", productId = "zyx987")`, this mapper
* would return `"ProductDetail"` as the destination's name, along with the following arguments:
* ```json
* {
* "userId": "123abc",
* "productId": "zyx987"
* }
* ```
*
* Returns `null` for any entries that can't be named (see [SerialName]). Sentry displays these
* entries as `"/unknown"` with no arguments.
*
* The argument limits described in [BackStackEntryMapper] apply.
*
* **Privacy / PII**
*
* This mapper returns arguments for every property of each back stack entry passed to it, which
* may include private data or PII. Almost all properties are sent as-is (see below for limited
* exceptions in the case of sensitive secrets). Neither `sendDefaultPii` nor the
* `dataCollection` options change what this mapper returns.
*
* Modify your use of this mapper if any entry in your back stack contains info you don't want
* sent to Sentry. For instance, i) use this mapper for all entries but filter out any
* properties you want to omit, or ii) use a custom [BackStackEntryMapper] that special-cases
* entries with sensitive info or PII and falls back to this mapper (or [SerialName]) for
* entries without it. See
* [Choosing Which Arguments to Send](https://docs.sentry.io/platforms/android/integrations/navigation/#choosing-which-arguments-to-send)
* for examples.
*
* **Limited filtering for sensitive secrets**
*
* Values are replaced with `"[Filtered]"` when their property's targeted name (i.e., their
* `@SerialName` if they have one, or else the property's name) contains a term from
* [Sentry's sensitive denylist](https://develop.sentry.dev/sdk/foundations/client/data-collection/#sensitive-denylist)
* (ignoring case). This filters secrets like `authToken`, but leaves PII like `userEmail`
* unchanged.
*
* Matching follows the same rule Sentry SDKs use for HTTP headers, cookies, and query
* parameters, meaning it may filter harmless properties like `insideCart` (`sid`) or `keyword`
* (`key`).
*
* **Encoding and encoding failures**
*
* Properties are encoded on the first argument read, including by `equals` or `hashCode`.
*
* Failures preserve the entry's name and replace its arguments with a drop reason, e.g.,
* `{"dropped_by_sentry": "encoding_failed"}`. Encoding errors are logged once per entry type
* when `debug` is enabled.
*/
@get:ApiStatus.Experimental
public val SerialNameAndProperties: BackStackEntryMapper<Any>
get() = BuiltInBackStackEntryMappers.serialNameAndProperties
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,23 @@ internal object BuiltInBackStackEntryMappers {
// threads may each create and probe a mapper and log warnings, and all but the first
// published instance would be discarded.
create(logger) {
KotlinxBackStackEntryMapper(logger = logger)
KotlinxBackStackEntryMapper(includeProperties = false, logger = logger)
}
}

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ The host app's `BackStackEntryMapper` supplies each entry's name and optional ar
`SentryBackStackEntry`. Properties are the fields and values on the host's back stack entry;
arguments are the values the mapper chooses to expose as `SentryBackStackEntry.arguments`.

When a host app uses the built-in `SerialNameAndProperties` mapper, the SDK maps entry properties to
arguments itself, in the [kotlinx subpackage](kotlinx/README.md). Hence `SerialNameAndProperties` and
`KotlinxPropertiesEncoder`, but `SentryBackStackEntry(arguments = ...)`. A custom mapper performs
that mapping on its end and hands us the resulting arguments.

Arguments are the mapper's output before sanitization. `BackStackConverter` normalizes entry names
and sanitizes arguments before they are recorded. Sanitization can stringify values or drop an
entry's arguments when they are invalid or exceed the limits in `ArgumentConstraints`.
Expand Down
Loading
Loading