Skip to content

feat(nav3): Add the built-in SerialName BackStackEntryMapper - #6780

Open
0xadam-brown wants to merge 4 commits into
mainfrom
feat/nav3-serial-name-stack-base
Open

0xadam-brown wants to merge 4 commits into
mainfrom
feat/nav3-serial-name-stack-base

Conversation

@0xadam-brown

@0xadam-brown 0xadam-brown commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

PR Stack (Nav3 SerialName Mapper)

This stack replaces the SerialName half of #6696. The SerialNameAndProperties mapper will follow in its own stack.


📜 Description

PR stack adds BackStackEntryMapper.SerialName, a built-in mapper for apps whose Nav3 back stack keys are @Serializable.

Each entry is named after its kotlinx.serialization serial name. (A built-in mapper that records both the serial name and properties of each back stack entry will be introduced in the next PR stack.)

Before

Extracting Sentry data from back stack entries was the responsibility of host apps via custom implementations of the BackStackEntryMapper interface. Like this:

 SentryNavEffect(
    backStack = navBackStack,
    // The host app had to implement its own custom mapper
    backStackEntryMapper = BackStackEntryMapper<NavKey> { entry -> 
      when (entry) {
        is Home -> SentryBackStackEntry(Home.serializer().descriptor.serialName)
        is ProductDetail -> SentryBackStackEntry(
          name = ProductDetail.serializer().descriptor.serialName,
          arguments = mapOf("product_id" to entry.productId)
        )
       // And so on for every destination in app...
    },
    options = SentryNavOptions(),
  )

After

Now host apps can use the built-in mapper instead of implementing their own ...

  SentryNavEffect(
    backStack = navBackStack,
    backStackEntryMapper = BackStackEntryMapper.SerialName,
    options = SentryNavOptions(),
  )

...or as a fallback within their own custom mapper:

 SentryNavEffect(
    backStack = navBackStack,
    backStackEntryMapper = BackStackEntryMapper<NavKey> { entry -> 
      when (entry) {
        is ProductDetail -> SentryBackStackEntry(
          name = ProductDetail.serializer().descriptor.serialName,
          arguments = mapOf("product_id" to entry.productId)
        )

        else -> BackStackEntryMapper.SerialName.map(entry)
    },
    options = SentryNavOptions(),
  )

Bonus points

I've also introduced:

  1. logic for recording why an entry is /unknown, whether for built-in mappers or (existing) custom mappers (see the new unknown_entry_reason field);
  2. robust regression tests verifying that the new mapper behaves correctly despite R8 obfuscation; and
  3. bit rot tests against newer kotlinx-serialization-core versions than the baseline we compile against.

And as usual the first PR does a bit of refactoring to make sure we're keeping things tidy.

PR by PR

Part What it adds
1 One internal home for the keys and values the Sentry UI shows, and a simpler argument sanitizer. No behavior change.
2 unknown_entry_reason for any mapper: unmapped, blank_name, and mapping_failed
3 The SerialName mapper, its SerialName-specific reasons, and kotlinx.serialization 1.7.3+ as a compileOnly dependency
4 The Android Nav3 samples use SerialName
5 An R8 check app that verifies names and reasons in minified builds, and CI that runs it against the oldest and newest supported kotlinx.serialization

💡 Motivation and Context

With Nav3, host apps manage their own nav back stack, which they implement as a list of arbitrarily typed entries. In order to be displayed in Sentry, each of those entries has to be mapped to a Sentry name (e.g., ProductDetailScreen) and zero or more arguments (e.g., productId="123abc"). There are two ways for us to get those mappings:

  1. via a custom BackStackEntryMapper the host app implements itself; or
  2. via an out-of-the-box mapper we provide.

Supporting SAGP auto-instrumentation for Nav3 relies on (2). This PR stack and the SerialNameAndProperties stack (#6696) give us the mappers we need. (Nav3 auto-instrumentation will be implemented in subsequent PRs.)

addresses: JAVA-787 (link)

💚 How did you test it?

(See each PR.)

📝 Checklist

  • I added GH Issue ID & Linear ID
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.
  • Public API changes reviewed by another Mobile SDK team member or implemented according to the develop docs spec.

🔮 Next steps

  • Document SerialName and the unknown_entry_reason values in sentry-docs, including the Troubleshooting section the KDoc links to.
  • A second stack for SerialNameAndProperties.

🤖 Generated with Claude Code

#skip-changelog

@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor
Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against e0c5425

@sentry

sentry Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
SDK Size io.sentry.tests.size 8.67.0 (1) release

⚙️ sentry-android Build Distribution Settings

@0xadam-brown
0xadam-brown marked this pull request as ready for review November 27, 2026 17:23
0xadam-brown added a commit to getsentry/sentry-docs that referenced this pull request Nov 30, 2026
Update Android navigation docs to describe the SerialName built-in mapper from [sentry-java#6780](getsentry/sentry-java#6780).

Describe mapper selection, privacy behavior, and serializer lookup caveats. Update examples to use built-in mapping and a selective custom fallback.
0xadam-brown added a commit to getsentry/sentry-docs that referenced this pull request Nov 30, 2026
Update Android navigation docs to describe the SerialName built-in mapper from [sentry-java#6780](getsentry/sentry-java#6780).

Describe mapper selection, privacy behavior, and serializer lookup caveats. Update examples to use built-in mapping and a selective custom fallback.
…ArgumentSanitizer (#6702)

The keys and values the Sentry UI shows (context, breadcrumb, and
transaction keys, the /unknown name, and the argument drop reasons and
limits) now live in one internal contract package, which the lifecycle
package may import. A test pins each displayed string.

ArgumentSanitizer recurses directly instead of through visit/exit
helpers, checks a CharSequence's length before copying it, and has its
own test suite.
@0xadam-brown
0xadam-brown requested review from a team and adinauer as code owners December 4, 2026 13:16
@0xadam-brown
0xadam-brown requested review from romtsn and runningcode and removed request for a team December 4, 2026 13:16
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Dec 4, 2026
@github-actions

github-actions Bot commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

PR risk: medium

For commit e0c5425.

Main concerns: data sent to Sentry, public contract, reach.

Rules that block low also fired:

  • R1: code was truncated, omitted or a reduced context was used: sentry-android-navigation3/src/test/kotlin/io/sentry/compose/navigation3/internal/backstack/ArgumentSanitizerTest.kt, sentry-android-navigation3/src/test/kotlin/io/sentry/compose/navigation3/internal/backstack/BackStackConverterTest.kt, sentry-android-navigation3/src/test/kotlin/io/sentry/compose/navigation3/internal/backstack/BackStackObserverTest.kt, sentry-android-navigation3/src/test/kotlin/io/sentry/compose/navigation3/internal/backstack/CoordinatedBackStackObserverTest.kt, sentry-android-navigation3/src/test/kotlin/io/sentry/compose/navigation3/internal/backstack/NormalizedSentryBackStackEntryTest.kt and 4 more

This label is a hint for reviewers, not an approval.

@github-actions github-actions Bot removed the risk: medium PR risk score: medium label Dec 4, 2026
@github-actions github-actions Bot added the risk: medium PR risk score: medium label Dec 4, 2026
An entry recorded as /unknown didn't say why, so outside debug logs a
mapper that threw, returned a blank name, or chose not to name an entry
all looked the same. Record the reason next to the entry as
unknown_entry_reason in the back stack context and the nav
transaction's data, and as to_unknown_entry_reason and
from_unknown_entry_reason on breadcrumbs.

The values are mapping_failed, blank_name, and unmapped. A mapper that
throws now records mapping_failed as its unknown entry reason instead
of as its arguments' drop reason, so one cause has one name.
@github-actions github-actions Bot added risk: medium PR risk score: medium and removed risk: medium PR risk score: medium labels Dec 4, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

risk: medium PR risk score: medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant