Repository navigation
feat(nav3): [Part 3] Add the built-in SerialName mapper - #6703
0xadam-brown wants to merge 2 commits into
Conversation
|
📲 Install BuildsAndroid
|
PR risk: mediumFor commit Main concerns: public contract, dependencies customers inherit, reach. Rules that block low also fired:
This label is a hint for reviewers, not an approval. |
| @@ -0,0 +1,15 @@ | |||
| # Versions for sentry-android-navigation3's kotlinx.serialization compatibility checks, registered as | |||
There was a problem hiding this comment.
dependency-matrix.versions.toml catalog alongside our libs.versions.toml. (An earlier version of this PR called it nav3.versions.toml.)
It holds two kotlinx.serialization versions:
kotlinxSerialization-floor(1.7.3): the oldest version we support, which the module compiles against. Nothing references it withversion.ref, so Dependabot leaves it alone, and it only changes in a reviewed PR.kotlinxSerialization-latestStable: the newest release, which Dependabot keeps current. Tests run against the floor by default, or against this with-Pnav3TestKotlinx=latestStable.
Keeping the floor in libs.versions.toml would mean shielding it with a Dependabot ignore rule. But ignore rules match a dependency's group and name, so they'd block the latestStable bumps too.
The R8 emulator check in #6783 (Part 5) watches both catalogs, so changing either version starts a run.
My clanker told me multiple version catalogs is a common convention, but chime in if you have concerns.
6937bd5 to
c8bea42
Compare
19c6402 to
328049c
Compare
fb33ea0 to
9909415
Compare
c8bea42 to
1765464
Compare
BackStackEntryMapper.SerialName names each back stack entry after its kotlinx.serialization serial name, which R8 doesn't obfuscate, and records no properties. kotlinx-serialization-core is a compileOnly dependency at 1.7.3 or later. If the app's version can't be linked, the mapper falls back to naming every entry /unknown. The mapper returns null, which is public API, for entries it can't name, so it reports why through an internal per-thread side channel that the converter reads around each mapping call. Its reasons are entry_not_annotated, generic_entry_type, serializer_not_found, serializer_access_threw, and kotlinx_serialization_version. Unit tests run against the 1.7.3 floor by default, and against the latest stable release with -Pnav3TestKotlinx=latestStable.
…mapper - Check kotlinx.serialization linkage by looking up the built-in String serializer instead of SDK-owned probe types. The check runs no generated serializer, has no inconclusive result, and needs no consumer keep rule. - Rethrow fatal errors that reflection wraps, from both the serializer lookup and the descriptor read, in one place in the mapper. - Retry a lookup that failed on an interrupted thread instead of caching it. - Add a canary test that fails once kotlinx.serialization can look up a private object's serializer itself, so the private object fallback can then be removed. - Move UnknownEntryReasonReporter and the kotlinx.serialization floor and advice to a new internal.common package, so that the contract package holds only what the Sentry UI shows. Boundary tests keep common from importing anything but contract, or Android or AndroidX. - Document how custom mappers inherit reasons from built-in mappers they delegate to, and name unknown_entry_reason values rather than internal types in the public KDoc. Co-Authored-By: Claude Opus 5.5 <[email protected]>
9909415 to
199a45c
Compare
1765464 to
4fb6bb6
Compare
PR Stack (Nav3 SerialName Mapper)
This stack replaces the
SerialNamehalf of #6696.SerialNameAndPropertieswill follow in its own stack.📜 Description
This PR adds the simpler of our two planned built-in mappers,
BackStackEntryMapper.SerialName. Apps can pass it toSentryNavEffectinstead of writing a mapper for every destination. It names each entry after its serial name: the key's@SerialName, or else its fully qualified class name. It records no properties.Name resolution success...
For each entry type, the mapper checks that the class is
@Serializableand not generic, looks up its serializer by reflection, and reads the descriptor's serial name. The result is cached per type, so the reflection runs once per type rather than on every navigation.Lookups can fail for reasons that depend on the app: its types, its kotlinx.serialization version, and its R8 configuration. A failure only affects that type. Its entries are recorded as
/unknown, other types are still named, and the mapper logs one warning for the type....and failure
PR records an
unknown_entry_reasonfor every/unknownentry so developers can figure out what's going on without having to enable debug logging.💡 Motivation and Context
Apps that use kotlinx.serialization have already given each key a name that doesn't depend on its obfuscated class name. Reusing it saves them from writing and maintaining a mapper for every key type.
addresses: JAVA-787 (link)
The built-in mappers are currently properties and not methods. That follows Kotlin's convention of using properties for stable, cached values and lets callers pass a mapper directly to SentryNavEffect without needing to remember an instance themselves.
A method-based constructor is the obvious alternative, whether simply returning the current cached maps or creating customized versions based on caller-provided configs. That approach seemed a bit less idiomatic to me (and for now overdone) given our current use-cases, so I decided against it. But we could always introduce it in the future without breaking the current API.
...that said, chime in if you disagree!
💚 How did you test it?
📝 Checklist
sendDefaultPIIis enabled.🔮 Next steps
Continue with Part 4: Use the SerialName mapper in the Android samples.
🤖 Generated with Claude Code