Skip to content

Commit ff1303b

Browse files
committed
fix(core): gate dynamic route params behind sendDefaultPii
1 parent 766a03d commit ff1303b

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,7 @@ export const reactNavigationIntegration = ({
197197
let initialStateHandled: boolean = false;
198198
let stateChangeTimeout: ReturnType<typeof setTimeout> | undefined;
199199
let recentRouteKeys: string[] = [];
200+
let sendDefaultPii: boolean = false;
200201

201202
if (enableTimeToInitialDisplay) {
202203
NATIVE.initNativeReactNavigationNewFrameTracking().catch((reason: unknown) => {
@@ -208,6 +209,7 @@ export const reactNavigationIntegration = ({
208209
* Set the initial state and start initial navigation span for the current screen.
209210
*/
210211
const afterAllSetup = (client: Client): void => {
212+
sendDefaultPii = client.getOptions().sendDefaultPii === true;
211213
tracing = getReactNativeTracingIntegration(client);
212214
if (tracing) {
213215
idleSpanOptions = {
@@ -461,7 +463,7 @@ export const reactNavigationIntegration = ({
461463
latestNavigationSpan.setAttributes({
462464
'route.name': routeName,
463465
'route.key': route.key,
464-
...extractDynamicRouteParams(routeName, route.params),
466+
...(sendDefaultPii ? extractDynamicRouteParams(routeName, route.params) : {}),
465467
'route.has_been_seen': routeHasBeenSeen,
466468
'previous_route.name': previousRoute?.name,
467469
'previous_route.key': previousRoute?.key,

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,7 @@ describe('ReactNavigationInstrumentation', () => {
10541054

10551055
describe('dynamic route params', () => {
10561056
it('includes dynamic route params from [id] route', async () => {
1057-
setupTestClient();
1057+
setupTestClient({ sendDefaultPii: true });
10581058
jest.runOnlyPendingTimers(); // Flush the init transaction
10591059

10601060
// Navigate to a static screen first so previous_route.name is set to a known value
@@ -1085,7 +1085,7 @@ describe('ReactNavigationInstrumentation', () => {
10851085
});
10861086

10871087
it('includes dynamic route params from [...slug] catch-all route joined with /', async () => {
1088-
setupTestClient();
1088+
setupTestClient({ sendDefaultPii: true });
10891089
jest.runOnlyPendingTimers(); // Flush the init transaction
10901090

10911091
mockNavigation.navigateToCatchAllRoute();
@@ -1110,6 +1110,22 @@ describe('ReactNavigationInstrumentation', () => {
11101110
);
11111111
});
11121112

1113+
it('does not include dynamic route params when sendDefaultPii is disabled', async () => {
1114+
setupTestClient();
1115+
jest.runOnlyPendingTimers(); // Flush the init transaction
1116+
1117+
mockNavigation.navigateToDynamicRoute();
1118+
jest.runOnlyPendingTimers();
1119+
1120+
await client.flush();
1121+
1122+
const actualEvent = client.event;
1123+
const traceData = actualEvent?.contexts?.trace?.data as Record<string, unknown>;
1124+
1125+
expect(traceData[SEMANTIC_ATTRIBUTE_ROUTE_NAME]).toBe('profile/[id]');
1126+
expect(traceData['route.params.id']).toBeUndefined();
1127+
});
1128+
11131129
it('does not include non-dynamic params from static routes', async () => {
11141130
setupTestClient();
11151131
jest.runOnlyPendingTimers(); // Flush the init transaction
@@ -1131,6 +1147,7 @@ describe('ReactNavigationInstrumentation', () => {
11311147
setupOptions: {
11321148
beforeSpanStart?: (options: StartSpanOptions) => StartSpanOptions;
11331149
useDispatchedActionData?: boolean;
1150+
sendDefaultPii?: boolean;
11341151
} = {},
11351152
) {
11361153
const rNavigation = reactNavigationIntegration({
@@ -1146,6 +1163,7 @@ describe('ReactNavigationInstrumentation', () => {
11461163
const options = getDefaultTestClientOptions({
11471164
enableNativeFramesTracking: false,
11481165
enableStallTracking: false,
1166+
sendDefaultPii: setupOptions.sendDefaultPii,
11491167
tracesSampleRate: 1.0,
11501168
integrations: [rNavigation, rnTracing],
11511169
enableAppStartTracking: false,

0 commit comments

Comments
 (0)