Skip to content

Commit d56b7dc

Browse files
fix(tracing): Use route name instead of route key for current route tracking (#4650)
Co-authored-by: Krystof Woldrich <krystof.woldrich@sentry.io>
1 parent 539c9bd commit d56b7dc

File tree

3 files changed

+70
-1
lines changed

3 files changed

+70
-1
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
- Considers the `SENTRY_DISABLE_AUTO_UPLOAD` and `SENTRY_DISABLE_NATIVE_DEBUG_UPLOAD` environment variables in the configuration of the Sentry Android Gradle Plugin for Expo plugin ([#4583](https://github.com/getsentry/sentry-react-native/pull/4583))
2020
- Handle non-string category in getCurrentScreen on iOS ([#4629](https://github.com/getsentry/sentry-react-native/pull/4629))
21+
- Use route name instead of route key for current route tracking ([#4650](https://github.com/getsentry/sentry-react-native/pull/4650))
22+
- Using key caused user interaction transaction names to contain route hash in the name.
2123

2224
### Dependencies
2325

packages/core/src/js/tracing/reactnavigation.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ export const reactNavigationIntegration = ({
326326
},
327327
});
328328

329-
tracing?.setCurrentRoute(route.key);
329+
tracing?.setCurrentRoute(route.name);
330330

331331
pushRecentRouteKey(route.key);
332332
latestRoute = route;

packages/core/test/tracing/reactnavigation.test.ts

+67
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,73 @@ describe('ReactNavigationInstrumentation', () => {
579579
});
580580
});
581581

582+
describe('setCurrentRoute', () => {
583+
let mockSetCurrentRoute: jest.Mock;
584+
585+
beforeEach(() => {
586+
mockSetCurrentRoute = jest.fn();
587+
const rnTracingIntegration = reactNativeTracingIntegration();
588+
rnTracingIntegration.setCurrentRoute = mockSetCurrentRoute;
589+
590+
const rNavigation = reactNavigationIntegration({
591+
routeChangeTimeoutMs: 200,
592+
});
593+
mockNavigation = createMockNavigationAndAttachTo(rNavigation);
594+
595+
const options = getDefaultTestClientOptions({
596+
enableNativeFramesTracking: false,
597+
enableStallTracking: false,
598+
tracesSampleRate: 1.0,
599+
integrations: [rNavigation, rnTracingIntegration],
600+
enableAppStartTracking: false,
601+
});
602+
603+
client = new TestClient(options);
604+
setCurrentClient(client);
605+
client.init();
606+
607+
jest.runOnlyPendingTimers();
608+
});
609+
610+
test('setCurrentRoute is called with route name after navigation', async () => {
611+
expect(mockSetCurrentRoute).toHaveBeenCalledWith('Initial Screen');
612+
613+
mockSetCurrentRoute.mockClear();
614+
mockNavigation.navigateToNewScreen();
615+
jest.runOnlyPendingTimers();
616+
617+
expect(mockSetCurrentRoute).toHaveBeenCalledWith('New Screen');
618+
619+
mockSetCurrentRoute.mockClear();
620+
mockNavigation.navigateToSecondScreen();
621+
jest.runOnlyPendingTimers();
622+
623+
expect(mockSetCurrentRoute).toHaveBeenCalledWith('Second Screen');
624+
625+
mockSetCurrentRoute.mockClear();
626+
mockNavigation.navigateToInitialScreen();
627+
jest.runOnlyPendingTimers();
628+
629+
expect(mockSetCurrentRoute).toHaveBeenCalledWith('Initial Screen');
630+
});
631+
632+
test('setCurrentRoute is not called when navigation is cancelled', async () => {
633+
mockSetCurrentRoute.mockClear();
634+
mockNavigation.emitCancelledNavigation();
635+
jest.runOnlyPendingTimers();
636+
637+
expect(mockSetCurrentRoute).not.toHaveBeenCalled();
638+
});
639+
640+
test('setCurrentRoute is not called when navigation finishes', async () => {
641+
mockSetCurrentRoute.mockClear();
642+
mockNavigation.finishAppStartNavigation();
643+
jest.runOnlyPendingTimers();
644+
645+
expect(mockSetCurrentRoute).not.toHaveBeenCalled();
646+
});
647+
});
648+
582649
function setupTestClient(
583650
setupOptions: {
584651
beforeSpanStart?: (options: StartSpanOptions) => StartSpanOptions;

0 commit comments

Comments
 (0)