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 nav 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;
  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

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

@github-actions

Copy link
Copy Markdown
Contributor
Fails
🚫 Please consider adding a changelog entry for the next release.
Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Instructions and example for changelog

Please add an entry to CHANGELOG.md to the "Unreleased" section. Make sure the entry includes this PR's number.

Example:

## Unreleased

### Features

- Add the built-in SerialName BackStackEntryMapper ([#6780](https://github.com/getsentry/sentry-java/pull/6780))

If none of the above apply, you can opt out of this check by adding #skip-changelog to the PR description or adding a skip-changelog label.

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

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