Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
### Fixes

- Fixes .env file loading in Expo sourcemap uploads ([#5210](https://github.com/getsentry/sentry-react-native/pull/5210))
- Fixes the issue with changing immutable metadata structure in the contructor of `ReactNativeClient`. This structure is getting re-created instead of being modified to ensure IP address is only inferred by Relay if `sendDefaultPii` is `true` ([#5202](https://github.com/getsentry/sentry-react-native/pull/5202))

### Dependencies

Expand Down
21 changes: 11 additions & 10 deletions packages/core/src/js/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,17 @@ export class ReactNativeClient extends Client<ReactNativeClientOptions> {
*/
public constructor(options: ReactNativeClientOptions) {
ignoreRequireCycleLogs(ReactNativeLibraries.ReactNativeVersion?.version);
options._metadata = options._metadata || {};
options._metadata.sdk = options._metadata.sdk || defaultSdkInfo;

// Only allow IP inferral by Relay if sendDefaultPii is true
if (options._metadata?.sdk) {
options._metadata.sdk.settings = {
infer_ip: options.sendDefaultPii ? 'auto' : 'never',
...options._metadata.sdk.settings,
};
}
options._metadata = {
...options._metadata,
sdk: {
...(options._metadata?.sdk || defaultSdkInfo),
settings: {
// Only allow IP inferral by Relay if sendDefaultPii is true
infer_ip: options.sendDefaultPii ? 'auto' : 'never',
...options._metadata?.sdk?.settings,
},
},
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

The changes follows the new implementation getsentry/sentry-javascript#17364

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, but the issue here is that the metadata structure is immutable so instead of modifying it we can construct a new one, and that's what I'm doing in this PR. Other than that, the logic stays pretty much the same.

I've also updated tests to reflect that change and indiciate the expected behaviour which is the following:

  • If sendDefaultPii is true, Sentry will infer the IP address of users' devices to events (errors, traces, replays, etc) in all browser-based SDKs.
  • If sendDefaultPii is false or not set, Sentry will not infer or collect IP address data.


// We default this to true, as it is the safer scenario
options.parentSpanIsAlwaysRootSpan =
Expand Down
12 changes: 6 additions & 6 deletions packages/core/test/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ describe('Tests ReactNativeClient', () => {
);
});

test('adds ip_address {{auto}} to user if set to undefined', () => {
test("doesn't change infer_ip if the ip_address is set to undefined", () => {
client.captureEvent({
user: {
ip_address: undefined,
Expand All @@ -692,13 +692,13 @@ describe('Tests ReactNativeClient', () => {
expect(mockTransportSend.mock.calls[0][firstArg][envelopeItems][0][envelopeItemPayload].sdk).toEqual(
expect.objectContaining({
settings: {
infer_ip: 'never',
infer_ip: 'auto',
},
}),
);
});

test('adds ip_address undefined to user if not set', () => {
test("doesn't change infer_ip if the user is not set", () => {
client.captureEvent({
user: {},
});
Expand All @@ -707,20 +707,20 @@ describe('Tests ReactNativeClient', () => {
expect(mockTransportSend.mock.calls[0][firstArg][envelopeItems][0][envelopeItemPayload].sdk).toEqual(
expect.objectContaining({
settings: {
infer_ip: 'never',
infer_ip: 'auto',
},
}),
);
});

test('leaves ip_address undefined to undefined user', () => {
test("doesn't change infer_ip if the event is empty", () => {
client.captureEvent({});

expect(mockTransportSend.mock.calls[0][firstArg][envelopeItems][0][envelopeItemPayload].user).toBeUndefined();
expect(mockTransportSend.mock.calls[0][firstArg][envelopeItems][0][envelopeItemPayload].sdk).toEqual(
expect.objectContaining({
settings: {
infer_ip: 'never',
infer_ip: 'auto',
},
}),
);
Expand Down
Loading