Skip to content

feat(core): Name navigation spans using dispatched action payload#5982

Merged
alwx merged 5 commits intomainfrom
alwx/improvement/4429
Apr 13, 2026
Merged

feat(core): Name navigation spans using dispatched action payload#5982
alwx merged 5 commits intomainfrom
alwx/improvement/4429

Conversation

@alwx
Copy link
Copy Markdown
Contributor

@alwx alwx commented Apr 13, 2026

📢 Type of change

  • Bugfix
  • New feature
  • Enhancement
  • Refactoring

📜 Description

When useDispatchedActionData is enabled, the ReactNavigationIntegration now extracts the route name from the dispatched action's payload.name and uses it to name the navigation span immediately at dispatch time, instead of starting with the generic "Route Change" name.

Fixes #4429

💚 How did you test it?

  • New unit tests are actually 90% of this PR :D

📝 Checklist

  • I added tests to verify 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.
  • All tests passing
  • No breaking changes

When `useDispatchedActionData` is enabled, extract the route name from
the dispatched action's `payload.name` (available for NAVIGATE, PUSH,
REPLACE, JUMP_TO actions) and use it to name the navigation span
immediately at dispatch time instead of the generic 'Route Change'.

Actions without a known route name in the payload (GO_BACK, POP,
POP_TO_TOP, RESET) no longer create navigation spans when
`useDispatchedActionData` is enabled, reducing noise.

The span name is still updated with the final route name from the
router's state change, unless `beforeStartSpan` has customized it.

Resolves #4429
@alwx alwx self-assigned this Apr 13, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 13, 2026

Semver Impact of This PR

None (no version bump detected)

📋 Changelog Preview

This is how your changes will appear in the changelog.
Entries from this PR are highlighted with a left border (blockquote style).


  • feat(core): Name navigation spans using dispatched action payload by alwx in #5982
  • ci: Gate size analysis on ready-to-merge label for PRs by antonis in #5963
  • chore(deps): update Android SDK to v8.38.0 by github-actions in #5971
  • chore(deps): update Sentry Android Gradle Plugin to v6.4.0 by github-actions in #5974
  • chore(deps): update Cocoa SDK to v9.10.0 by github-actions in #5972
  • chore(deps): update JavaScript SDK to v10.48.0 by github-actions in #5975
  • chore(deps): bump actions/github-script from 8 to 9 by dependabot in #5980
  • chore(deps): bump actions/create-github-app-token from 3.0.0 to 3.1.1 by dependabot in #5979
  • chore(deps): update Bundler Plugins to v5.2.0 by github-actions in #5968
  • chore(deps): bump axios from 1.13.5 to 1.15.0 by dependabot in #5978
  • chore(deps): bump addressable from 2.8.7 to 2.9.0 in /performance-tests by dependabot in #5969
  • chore(deps): bump basic-ftp from 5.2.0 to 5.2.2 by dependabot in #5977
  • fix(profiling): Fix app start transaction profile timestamp offset by antonis in #5962
  • fix(android): Use componentStack as fallback for missing error stack traces by antonis in #5965
  • chore(deps): bump addressable from 2.8.7 to 2.9.0 in /samples/react-native-macos by dependabot in #5967
  • chore(deps): bump addressable from 2.8.7 to 2.9.0 in /samples/react-native by dependabot in #5966
  • fix(ios): Add SENTRY_PROJECT_ROOT env var for monorepo support by antonis in #5961
  • feat(ios): Add attachAllThreads option by antonis in #5960
  • fix(core): Lazy-load Metro internal modules to prevent Expo 55 import errors by lucas-zimerman in #5958
  • chore(deps): update Cocoa SDK to v9.9.0 by github-actions in #5956
  • chore(deps): update Maestro to v2.4.0 by github-actions in #5955
  • Feat: Fallback to stacktrace parsing by lucas-zimerman in #5946
  • fix(ci): Bump Node to 22 in size-analysis and testflight workflows by antonis in #5954
  • feat(playground): Open Sentry in desktop browser from Expo apps by antonis in #5947

Plus 6 more


🤖 This preview updates automatically when you update the PR.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions bot commented Apr 13, 2026

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

Generated by 🚫 dangerJS against 461ba9b

@alwx alwx marked this pull request as ready for review April 13, 2026 12:41
Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Autofix Details

Bugbot Autofix prepared a fix for the issue found in the latest run.

  • ✅ Fixed: Dispatched route name applied when feature is disabled
    • I gated the dispatched route name assignment with useDispatchedActionData so default-mode spans keep the default name and empty route-change filtering remains effective.

Create PR

Or push these changes by commenting:

@cursor push 61e3ce524a
Preview (61e3ce524a)
diff --git a/packages/core/src/js/tracing/reactnavigation.ts b/packages/core/src/js/tracing/reactnavigation.ts
--- a/packages/core/src/js/tracing/reactnavigation.ts
+++ b/packages/core/src/js/tracing/reactnavigation.ts
@@ -391,7 +391,7 @@
     }
 
     const spanOptions = getDefaultIdleNavigationSpanOptions();
-    if (dispatchedRouteName) {
+    if (useDispatchedActionData && dispatchedRouteName) {
       spanOptions.name = dispatchedRouteName;
     }

This Bugbot Autofix run was free. To enable autofix for future PRs, go to the Cursor dashboard.

alwx added a commit to getsentry/sentry-docs that referenced this pull request Apr 13, 2026
Update the React Navigation integration docs to reflect the new behavior
of `useDispatchedActionData`: immediate span naming from action payload,
skipping spans for actions without a known route name, and filtering
non-navigation actions.

Ref: getsentry/sentry-react-native#5982
…ActionData

Ensure getRouteNameFromAction is only called when useDispatchedActionData
is enabled. Previously, the route name was extracted from the action
payload even when the feature was disabled, which could change the span
name and beforeStartSpan input for users who hadn't opted in.
…chedActionData

Two fixes based on PR review feedback:

1. Allow setup/programmatic calls (no event) to create the initial
   navigation span even when useDispatchedActionData is enabled. The
   early return for actions without payload.name now checks that an
   event exists, so afterAllSetup and registerNavigationContainer
   still work correctly.

2. Pass the actual span name to ignoreEmptyRouteChangeTransactions
   instead of the hardcoded default. This ensures orphaned spans
   created with a dispatched route name are still discarded when
   the state listener is never called.
Copy link
Copy Markdown
Contributor

@antonis antonis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🚀
Added a minor nit comment

@lucas-zimerman
Copy link
Copy Markdown
Collaborator

might be a nice idea to default it as true on the next major

@antonis
Copy link
Copy Markdown
Contributor

antonis commented Apr 13, 2026

might be a nice idea to default it as true on the next major

Good idea 👍 Let's open an issue for that if you agree Alex

@alwx alwx added the ready-to-merge Triggers the full CI test suite label Apr 13, 2026
@alwx alwx enabled auto-merge (squash) April 13, 2026 15:06
@alwx alwx merged commit 40fb54e into main Apr 13, 2026
60 of 103 checks passed
@alwx alwx deleted the alwx/improvement/4429 branch April 13, 2026 15:06
alwx added a commit to getsentry/sentry-docs that referenced this pull request Apr 13, 2026
Update the React Navigation integration docs to reflect the new behavior
of `useDispatchedActionData`:

- **Immediate span naming** from action payload (`NAVIGATE`, `PUSH`,
`REPLACE`, `JUMP_TO`)
- **Skip spans** for actions without a known route name (`GO_BACK`,
`POP`, `POP_TO_TOP`, `RESET`)
- **Filter non-navigation actions** (`SET_PARAMS`, drawer actions)
- Clarified that `goBack` transactions are skipped when the option is
enabled

Ref: getsentry/sentry-react-native#5982
@alwx
Copy link
Copy Markdown
Contributor Author

alwx commented Apr 13, 2026

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 461ba9b. Configure here.

if (useDispatchedActionData && event && !dispatchedRouteName && !isAppRestart) {
debug.log(`${INTEGRATION_NAME} Navigation action has no route name in payload, not starting navigation span.`);
return;
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dead !isAppRestart check in new condition

Low Severity

The !isAppRestart guard in the condition useDispatchedActionData && event && !dispatchedRouteName && !isAppRestart is dead code. Every call site where isAppRestart is true passes undefined as the event (startIdleNavigationSpan(undefined, true)), so the condition already short-circuits at event && before reaching !isAppRestart. Conversely, when event is truthy (from the __unsafe_action__ listener), isAppRestart is always false by default. This unreachable check is misleading and suggests isAppRestart matters for this branch when it never does. Flagging this because it was mentioned in the project review rules about unused code.

Fix in Cursor Fix in Web

Triggered by project rule: PR Review Guidelines for Cursor Bot

Reviewed by Cursor Bugbot for commit 461ba9b. Configure here.

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

Labels

ready-to-merge Triggers the full CI test suite

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ReactNativation] [ExpoRouter] Name navigation spans using dispatched action data

3 participants