Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
328049c
ref(nav3): Gather nav data keys in a contract package and simplify Arโ€ฆ
0xadam-brown Nov 27, 2026
9647502
docs(nav3): Add a README to the contract package
0xadam-brown Nov 30, 2026
175029f
feat(nav3): Record why back stack entries are /unknown
0xadam-brown Nov 27, 2026
199a45c
docs(nav3): Clarify when BackStackEntryMapper failures fall back to /โ€ฆ
0xadam-brown Nov 30, 2026
3b5c182
feat(nav3): Add the SerialName back stack mapper
0xadam-brown Nov 27, 2026
4fb6bb6
ref(nav3): Replace the compatibility probe and harden the SerialName โ€ฆ
0xadam-brown Nov 30, 2026
451cdc5
feat(nav3): Use the SerialName mapper in the Android samples
0xadam-brown Nov 27, 2026
ab11537
fix(samples): Reset the Nav3 performance counters when the mapper chaโ€ฆ
0xadam-brown Nov 30, 2026
d79f2a8
test(nav3): Verify the SerialName mapper under R8
0xadam-brown Nov 27, 2026
ae14145
test(nav3): Read the R8 check's names and reasons from what SentryNavโ€ฆ
0xadam-brown Nov 27, 2026
001bcd0
test(nav3): Tighten the R8 check and match it to the compatibility check
0xadam-brown Nov 30, 2026
4be993a
chore(nav3): Anchor the SerialNameAndProperties mapper PR stack
0xadam-brown Dec 1, 2026
9b41e0d
feat(nav3): [Part 1] Define an Arguments Protocol when converting bacโ€ฆ
0xadam-brown Dec 4, 2026
65aadcb
feat(nav3): [Part 2] Add an argument source for encoding back stack eโ€ฆ
0xadam-brown Dec 4, 2026
dae3887
feat(nav3): [Part 3] Introduce the built-in SerialNameAndProperties mโ€ฆ
0xadam-brown Dec 4, 2026
bbdd9c9
feat(nav3): [Part 4] Use the SerialNameAndProperties mapper in the Naโ€ฆ
0xadam-brown Dec 4, 2026
ea1924e
test(nav3): Verify the SerialNameAndProperties mapper under R8 in CI โ€ฆ
0xadam-brown Dec 4, 2026
c8426d6
feat(nav3): Record why back stack entries are /unknown
0xadam-brown Nov 27, 2026
678f30c
docs(nav3): Clarify when BackStackEntryMapper failures fall back to /โ€ฆ
0xadam-brown Nov 30, 2026
8e6872c
feat(nav3): Add the SerialName back stack mapper
0xadam-brown Nov 27, 2026
bf6b05c
ref(nav3): Replace the compatibility probe and harden the SerialName โ€ฆ
0xadam-brown Nov 30, 2026
fea3c72
docs(nav3): Fix the SerialName KDoc's link to the troubleshooting docs
0xadam-brown Nov 30, 2026
dc6955b
feat(nav3): Use the SerialName mapper in the Android samples
0xadam-brown Nov 27, 2026
d30d2b3
fix(samples): Reset the Nav3 performance counters when the mapper chaโ€ฆ
0xadam-brown Nov 30, 2026
e8d6ea3
feat(samples): Let scripted Nav3 performance runs choose the mapper
0xadam-brown Nov 30, 2026
e9c14fc
test(nav3): Verify the SerialName mapper under R8
0xadam-brown Nov 27, 2026
b805f4c
test(nav3): Read the R8 check's names and reasons from what SentryNavโ€ฆ
0xadam-brown Nov 27, 2026
37052fa
test(nav3): Tighten the R8 check and match it to the compatibility check
0xadam-brown Nov 30, 2026
8ab80f1
docs(nav3): Fix the R8 check's links to the named-companion docs
0xadam-brown Nov 30, 2026
e5f924e
Merge branch 'feat/nav3-serial-name-stack-5' into feat/nav3-serial-naโ€ฆ
0xadam-brown Dec 4, 2026
221715f
Merge branch 'feat/nav3-serial-name-stack-5' into feat/nav3-serial-naโ€ฆ
0xadam-brown Dec 4, 2026
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
6 changes: 3 additions & 3 deletions .github/workflows/integration-tests-nav3-r8.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Nav3 Built-in Back Stack Mappers R8 Check

# Verifies behavior of BackStackEntryMapper.SerialName from sentry-android-navigation3 in
# R8-minified builds on an emulator. Runs tests in:
# Verifies behavior of BackStackEntryMapper.SerialName and SerialNameAndProperties from
# sentry-android-navigation3 in R8-minified builds on an emulator. Runs tests in:
#
# - R8 full mode against the compile floor of kotlinx-serialization-core and its latest stable
# release; and
Expand Down Expand Up @@ -34,7 +34,7 @@ on:
- 'gradle/dependency-matrix.versions.toml'
- 'buildSrc/**'
- 'build-logic/**'
# Utilities the mapper uses to handle exceptions.
# Utilities the mappers use to handle exceptions and filter sensitive arguments.
- 'sentry/src/main/java/io/sentry/util/**'
pull_request:
paths: *nav3-r8-paths
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,17 @@
### 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

- Nav3: Record why a back stack entry is `/unknown` via an `unknown_entry_reason` next to it in the Sentry UI ([#6801](https://github.com/getsentry/sentry-java/pull/6801))
- A `BackStackEntryMapper` that throws now records `"unknown_entry_reason": "mapping_failed"` instead of `"dropped_by_sentry": "mapping_failed"` in the entry's arguments.

### Behavioral Changes

- Nav3: `SentryNavOptions.maxCapturedBackStackEntries` is now capped at 25, and larger values are treated as 25 ([#6707](https://github.com/getsentry/sentry-java/pull/6707))

### Fixes

- Session Replay: Stop dropping or freezing video when the device clock changes mid-recording ([#6542](https://github.com/getsentry/sentry-java/pull/6542))
Expand Down
29 changes: 21 additions & 8 deletions scripts/test-nav3-built-in-back-stack-mappers-r8.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env bash
# Verifies BackStackEntryMapper.SerialName in R8-minified builds on a booted emulator or device.
# Verifies BackStackEntryMapper.SerialName and SerialNameAndProperties in R8-minified builds on a
# booted emulator or device. Each APK is launched once per mapper.
# See sentry-android-integration-tests/nav3-built-in-back-stack-mappers-r8-check/README.md.
#
# Usage:
Expand All @@ -12,6 +13,7 @@ module="nav3-built-in-back-stack-mappers-r8-check"
moduleDir="sentry-android-integration-tests/nav3-built-in-back-stack-mappers-r8-check"
appId="io.sentry.tests.nav3.r8"
tag="NAV3_R8_CHECK"
mappers=(SerialName SerialNameAndProperties)

copyApk() {
cp "${moduleDir}/build/outputs/apk/release/nav3-built-in-back-stack-mappers-r8-check-release.apk" "$1"
Expand Down Expand Up @@ -47,17 +49,20 @@ build() {
done
}

# Installs and launches APK $1, prints its check's output, and fails unless the check passed.
# Installs and launches APK $1 to check mapper $2, prints its check's output, and fails unless the
# check passed.
runApk() {
local apk="$1"
local mapper="$2"
adb uninstall "$appId" > /dev/null 2>&1 || true
adb install "$apk" > /dev/null || return 1
# Reads only this launch's lines, so the previous APK's RESULT=PASS can't hide a failure. The
# timestamp has second precision, hence the sleep.
local since
sleep 1
since="$(adb shell "date +'%m-%d %H:%M:%S.000'" | tr -d '\r')" || return 1
adb shell am start -W -n "${appId}/.BuiltInBackStackMappersActivity" > /dev/null || return 1
adb shell am start -W -n "${appId}/.BuiltInBackStackMappersActivity" --es mapper "$mapper" \
> /dev/null || return 1

local output=""
for _ in $(seq 1 60); do
Expand All @@ -78,6 +83,12 @@ runApk() {
adb logcat -d -T "$since" -b crash | grep -A 20 "$appId" || true
return 1
fi
# The Activity checks SerialName if the extra is missing, so a launch that passed for the wrong
# mapper would otherwise go unnoticed.
if ! sed -E "s/^.*${tag}: //" <<< "$output" | tr -d '\r' | grep -qx "MAPPER=${mapper}"; then
echo "Expected MAPPER=${mapper}, but the Activity checked another mapper."
return 1
fi
}

run() {
Expand All @@ -94,11 +105,13 @@ run() {
for apk in "${apks[@]}"; do
local name
name="$(basename "$apk" .apk)"
echo "=== $name"
if ! runApk "$apk"; then
echo "FAILED: $name"
failed=1
fi
for mapper in "${mappers[@]}"; do
echo "=== $name ($mapper)"
if ! runApk "$apk" "$mapper"; then
echo "FAILED: $name ($mapper)"
failed=1
fi
done
done

if [[ $failed -ne 0 ]]; then
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# nav3-built-in-back-stack-mappers-r8-check

Checks that `BackStackEntryMapper.SerialName` works after R8 obfuscation:
Checks that `BackStackEntryMapper.SerialName` and `BackStackEntryMapper.SerialNameAndProperties` work after R8 obfuscation:

- The names and `unknown_entry_reason`s that `SentryNavEffect` records in the `Navigation` context match expectations.
- The mapper's kotlinx.serialization compatibility check passes.
- R8 actually obfuscates a representative class.
- The names, `unknown_entry_reason`s, and arguments that `SentryNavEffect` records in the `Navigation` context match expectations.
- The mappers' kotlinx.serialization compatibility checks pass.
- R8 actually obfuscates a representative class, and the fields of a class whose properties are recorded.

The app uses kotlinx.serialization's consumer rules and its own `proguard-rules.pro`; the SDK supplies no keep rules for app serialization
classes.
Expand All @@ -18,7 +18,8 @@ Boot an emulator or device, then run:
```

Versions come from `gradle/dependency-matrix.versions.toml`. Both floor and latestStable run in R8 full mode; floor also runs in compat mode
to cover older named-companion rules. Each APK must report `RESULT=PASS`.
to cover older named-companion rules. Each APK is launched once per mapper (`--es mapper SerialName` or `SerialNameAndProperties`), and
each launch must report `RESULT=PASS`.

CI also runs the module's unit tests against latestStable.

Expand All @@ -31,6 +32,6 @@ upgrade and passing checks. Closing the PR tells Dependabot to ignore that versi
compilers may still work.

**Test failure:** investigate changes to serializer lookup, serial descriptors, or R8 rules. Fix incorrect names or unexpected `/unknown`
results, then merge the fix with the update.
results or arguments, then merge the fix with the update.

Preserve support for the floor in either case; see "Version floor" in the `kotlinx` package README.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Checks BackStackEntryMapper.SerialName in R8-minified release builds. See README.md.
// Checks the built-in BackStackEntryMappers in R8-minified release builds. See README.md.
plugins {
id("com.android.application")
alias(libs.plugins.kotlin.android)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ import io.sentry.compose.navigation3.SentryNavOptions
import kotlinx.coroutines.delay

/**
* Shows every [Expectation]'s key as one back stack to `SentryNavEffect` with
* `BackStackEntryMapper.SerialName`, and reports the names and reasons it records.
* Shows every [Expectation]'s key as one back stack to `SentryNavEffect` with the built-in mapper
* named by the [MAPPER_EXTRA] intent extra (`BackStackEntryMapper.SerialName` by default), and
* reports the names, reasons, and arguments it records.
*
* Only one `SentryNavEffect` records an Activity's back stack, so each mapper needs its own launch.
*
* An exception crashes the Activity, which the runner script reports as a failure.
*/
Expand All @@ -23,6 +26,20 @@ class BuiltInBackStackMappersActivity : ComponentActivity() {
super.onCreate(savedInstanceState)

// Before the mapper's first map() call, which runs its compatibility check.
val mapperName = intent.getStringExtra(MAPPER_EXTRA) ?: SERIAL_NAME
val includeProperties =
when (mapperName) {
SERIAL_NAME -> false
SERIAL_NAME_AND_PROPERTIES -> true
else -> error("Unknown $MAPPER_EXTRA: $mapperName")
}
val mapper =
if (includeProperties) {
BackStackEntryMapper.SerialNameAndProperties
} else {
BackStackEntryMapper.SerialName
}

val logger = RecordingLogger()
val recorder = BackStackRecorder()
initSentry(this, logger, recorder)
Expand All @@ -45,7 +62,7 @@ class BuiltInBackStackMappersActivity : ComponentActivity() {
}

setContent {
SentryNavEffect(backStack, BackStackEntryMapper.SerialName, options)
SentryNavEffect(backStack, mapper, options)

LaunchedEffect(Unit) {
// The back stack reaches the scope once the effect holds the Activity's nav lease.
Expand All @@ -55,18 +72,27 @@ class BuiltInBackStackMappersActivity : ComponentActivity() {
if (recorded != null) break
delay(RECORD_RETRY_MILLIS)
}
report(expectations, recorded?.reversed(), logger, recorder.lastEventSummary)
report(
mapperName,
includeProperties,
expectations,
recorded?.reversed(),
logger,
recorder.lastEventSummary,
)
}
}
}

private fun report(
mapperName: String,
includeProperties: Boolean,
expectations: List<Expectation>,
recorded: List<RecordedEntry>?,
logger: RecordingLogger,
lastEventSummary: String,
) {
val lines = mutableListOf<String>()
val lines = mutableListOf("MAPPER=$mapperName")
var failures = 0

if (recorded?.size != expectations.size) {
Expand All @@ -83,8 +109,11 @@ class BuiltInBackStackMappersActivity : ComponentActivity() {
entry.unknownEntryReason == null
val unnamedAsExpected =
unnamed && entry.unknownEntryReason in expectation.unknownEntryReasons
// SerialName never returns arguments, so no entry it maps may have any.
val passed = !entry.hasArguments && (namedAsExpected || unnamedAsExpected)
// SerialName returns no arguments, and an unnamed entry has none with either mapper.
val expectedArguments =
if (includeProperties && !unnamed) expectation.expectedArguments else null
val argumentsAsExpected = entry.arguments == expectedArguments
val passed = argumentsAsExpected && (namedAsExpected || unnamedAsExpected)
val fellBack = expectation.expected != null && unnamedAsExpected

if (!passed) failures++
Expand All @@ -93,7 +122,11 @@ class BuiltInBackStackMappersActivity : ComponentActivity() {
"${if (passed) "PASS" else "FAIL"} ${expectation.label} " +
"(runtime class ${expectation.key.javaClass.name}): " +
"expected=${expectation.expected?.let { "/$it" } ?: UNKNOWN} actual=${entry.name}" +
(if (entry.hasArguments) " (has arguments)" else "") +
(if (!argumentsAsExpected) {
" arguments=${entry.arguments} (expected $expectedArguments)"
} else {
""
}) +
(if (unnamed) {
" reason=${entry.unknownEntryReason} (expected ${expectation.unknownEntryReasons})"
} else if (entry.unknownEntryReason != null) {
Expand All @@ -114,11 +147,19 @@ class BuiltInBackStackMappersActivity : ComponentActivity() {
lines.forEach { Log.i(TAG, it) }
}

private companion object {
const val TAG = "NAV3_R8_CHECK"
const val UNKNOWN = "/unknown"
const val RECORD_ATTEMPTS = 50
const val RECORD_RETRY_MILLIS = 100L
companion object {
/**
* The intent extra that names the mapper to check: [SERIAL_NAME] (the default) or
* [SERIAL_NAME_AND_PROPERTIES].
*/
const val MAPPER_EXTRA = "mapper"
const val SERIAL_NAME = "SerialName"
const val SERIAL_NAME_AND_PROPERTIES = "SerialNameAndProperties"

private const val TAG = "NAV3_R8_CHECK"
private const val UNKNOWN = "/unknown"
private const val RECORD_ATTEMPTS = 50
private const val RECORD_RETRY_MILLIS = 100L
}
}

Expand All @@ -128,7 +169,8 @@ class Check(val description: String, val passed: Boolean)
/**
* A back stack key and the name `SentryNavEffect` should record for it with
* [BackStackEntryMapper.SerialName], or `null` if it should be unnamed, with one of
* [unknownEntryReasons].
* [unknownEntryReasons]. [expectedArguments] are the arguments it should record for a named key
* with [BackStackEntryMapper.SerialNameAndProperties], or `null` if none.
*
* A key with an [expected] name may also have [unknownEntryReasons], if neither
* kotlinx.serialization nor R8 guarantees whether it can be named. It may then instead be recorded
Expand All @@ -139,6 +181,7 @@ class Expectation(
val key: Any,
val expected: String?,
val unknownEntryReasons: Set<String> = emptySet(),
val expectedArguments: Map<String, Any?>? = null,
) {
init {
require(expected != null || unknownEntryReasons.isNotEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,14 @@ fun compatibilityLogChecks(logger: RecordingLogger): List<Check> {
}

/**
* The prefixes of the messages the mapper logs when its compatibility check fails, or a built-in
* mapper can't be created.
* The prefixes of the messages the mapper logs when one of its compatibility checks fails, or a
* built-in mapper can't be created.
*
* See `KotlinxMapperDiagnostics` and `BuiltInBackStackEntryMappers` in sentry-android-navigation3.
*/
private val COMPATIBILITY_MESSAGE_PREFIXES =
listOf(
"Nav3 couldn't verify kotlinx.serialization compatibility",
"Nav3 SerialNameAndProperties is incompatible",
"Nav3 built-in mapper creation failed",
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ const val SERIALIZER_NOT_FOUND = "serializer_not_found"
const val SERIALIZER_ACCESS_THREW = "serializer_access_threw"

/** One back stack entry as SentryNavEffect records it in the `Navigation` context. */
class RecordedEntry(val name: String?, val unknownEntryReason: String?, val hasArguments: Boolean)
class RecordedEntry(val name: String?, val unknownEntryReason: String?, val arguments: Map<*, *>?) {
val hasArguments: Boolean
get() = arguments != null
}

/**
* Captures the back stack SentryNavEffect records, by reading the `Navigation` context of an event
Expand Down Expand Up @@ -55,7 +58,7 @@ class BackStackRecorder : SentryOptions.BeforeSendCallback {
RecordedEntry(
name = fields["entry"] as String?,
unknownEntryReason = fields["unknown_entry_reason"] as String?,
hasArguments = "entry_arguments" in fields,
arguments = fields["entry_arguments"] as Map<*, *>?,
)
}

Expand Down
Loading
Loading