Skip to content

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

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

0xadam-brown wants to merge 1 commit 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 8fb26b4

@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.65.1 (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.

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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant