feat(core): Name navigation spans using dispatched action payload#5982
feat(core): Name navigation spans using dispatched action payload#5982
Conversation
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
Semver Impact of This PR⚪ None (no version bump detected) 📋 Changelog PreviewThis is how your changes will appear in the changelog.
Plus 6 more 🤖 This preview updates automatically when you update the PR. |
|
There was a problem hiding this comment.
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.
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.
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.
antonis
left a comment
There was a problem hiding this comment.
LGTM 🚀
Added a minor nit comment
|
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 |
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
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ 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; | ||
| } |
There was a problem hiding this comment.
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.
Triggered by project rule: PR Review Guidelines for Cursor Bot
Reviewed by Cursor Bugbot for commit 461ba9b. Configure here.



📢 Type of change
📜 Description
When
useDispatchedActionDatais enabled, theReactNavigationIntegrationnow extracts the route name from the dispatched action'spayload.nameand 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?
📝 Checklist
sendDefaultPIIis enabled