Skip to content

feat(nav3): Add the built-in SerialNameAndProperties BackStackEntryMapper - #6696

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

0xadam-brown wants to merge 1 commit into
feat/nav3-serial-name-stack-5from
feat/nav3-serial-name-mappers-base

Conversation

@0xadam-brown

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

Copy link
Copy Markdown
Member

PR Stack (Nav3 SerialNameAndProperties Mapper)

This stack follows the SerialName stack (#6780) and is based on its last PR, #6783.


📜 Description

Introduces BackStackEntryMapper.SerialNameAndProperties, the second of two built-in mappers for kotlinx.serialization. (See the "Motivation and Context" section below for more info about why we need mappers in the first place.) The first, SerialName, was added by the #6780 PR stack.

For an entry like this...

@Serializable
@SerialName("ProductDetailScreen")
data class ProductDetail(val productId: String = "123", val authToken: String = "secret",)

...the two built-in mappers create Sentry data like this:

Built-in mapper Entry name Entry arguments
SerialName (#6780) "/ProductDetailScreen" n/a
SerialNameAndProperties "/ProductDetailScreen" {"productId": "123", "authToken": "[Filtered]" }

The high-level processing path for SerialNameAndProperties

For the top entry in the host app's nav stack
  → look up kotlinx serializer + descriptor
    → derive stable serial name
      → optionally deserialize properties as arguments
        → filter sensitive properties
          → enforce argument size / structure limits
            → record serial name + (optional) arguments as navigation data

Failure modes

  • If an entry can't be deserialized or its name isn't recoverable, it's given the name "/unknown" and an unknown_entry_reason (just like with SerialName).
  • If an entry's arguments can't be encoded, the entry's name is kept but its arguments are dropped with {"dropped_by_sentry": "encoding_failed"}.
  • If the host app's kotlinx-serialization-core version can't run our properties encoder, entries keep their names but the arguments of every entry with properties are dropped with "encoding_failed". (If the version is incompatible with the mapper itself, every entry is recorded as "/unknown" with unknown_entry_reason "kotlinx_serialization_version", as with SerialName.)

💡 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 SerialName stack give us the mappers we need. (Nav3 auto-instrumentation will be implemented in subsequent PRs.)

addresses: JAVA-787 (link)

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 has 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, whether as-is...

Like this:

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

...or filtering out sensitive / unwanted properties...

SentryNavEffect(
    backStack = navBackStack,
    backStackEntryMapper = BackStackEntryMapper<NavKey> { entry ->
      BackStackEntryMapper.SerialNameAndProperties.map(entry)?.let { mapped ->
        SentryBackStackEntry(
          name = mapped.name,
          arguments = mapped.arguments?.filterKeys { it != "userEmail" },
        )
      }
    },
    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.SerialNameAndProperties.map(entry)
    },
    options = SentryNavOptions(),
  )

This PR stack covers all the gory details of what introducing that built-in mapper requires. Have fun!

PR by PR

Part What it adds
1 The ArgumentSink seam back in ArgumentSanitizer, and KotlinxPropertiesEncoder, which encodes an entry's properties within the argument limits and filters sensitive keys
2 KotlinxArgumentSource, which encodes an entry's properties lazily, and the encoding_failed drop reason
3 The SerialNameAndProperties mapper and its encoder compatibility check
4 The Android Nav3 samples use SerialNameAndProperties, and the Performance tab can measure it
5 The R8 check app from #6783 also checks SerialNameAndProperties

addresses: JAVA-787 (link)

🔍 Due diligence

See the "Callouts" section in #6707 for a discussion of the performance impact of this PR stack, as well as leak memory concerns, and potential for crashing the host app. (Spoiler alert: no issues were found.)

💚 How did you test it?

(See individual PRs.)

📝 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

#skip-changelog

@github-actions

github-actions Bot commented Nov 20, 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 4be993a

@sentry

sentry Bot commented Nov 20, 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 changed the title feat(nav3): Add built-in serial name mappers feat(nav3): Add built-in BackStackEntryMappers for kotlinx.serialization Nov 20, 2026
@0xadam-brown
0xadam-brown marked this pull request as ready for review November 20, 2026 16:23
@0xadam-brown
0xadam-brown force-pushed the feat/nav3-serial-name-mappers-base branch from 3dc7c0a to 0441799 Compare November 24, 2026 10:20
@0xadam-brown
0xadam-brown marked this pull request as draft November 25, 2026 15:37
@0xadam-brown
0xadam-brown changed the base branch from main to feat/nav3-serial-name-stack-5 December 1, 2026 01:31
@0xadam-brown
0xadam-brown force-pushed the feat/nav3-serial-name-mappers-base branch from 0441799 to 4be993a Compare December 1, 2026 01:31
@0xadam-brown 0xadam-brown changed the title feat(nav3): Add built-in BackStackEntryMappers for kotlinx.serialization feat(nav3): Add the built-in SerialNameAndProperties BackStackEntryMapper Dec 1, 2026
@0xadam-brown
0xadam-brown marked this pull request as ready for review December 1, 2026 01:49

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