Skip to content

Commit a8caa5e

Browse files
Fix(V7): missing ip settings from SDK package (#5137)
* fix deprecated ip * changelog and lint fix * Apply suggestions from code review * Apply suggestions from code review
1 parent 95aaf8a commit a8caa5e

File tree

3 files changed

+57
-18
lines changed

3 files changed

+57
-18
lines changed

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,23 @@
88
99
## Unreleased
1010

11+
### Important Changes
12+
13+
This release includes a fix for a [behaviour change](https://docs.sentry.io/platforms/javascript/migration/v8-to-v9/#behavior-changes)
14+
that was originally fixed on version 6.21.0 of the React Native SDK: User IP Addresses should only be added to Sentry events automatically,
15+
if `sendDefaultPii` was set to `true`.
16+
17+
To avoid making a major bump, the fix was patched on the current version and not by bumping to V8.
18+
There is _no API_ breakage involved and hence it is safe to update.
19+
However, after updating the SDK, events (errors, traces, replays, etc.) sent from the browser, will only include
20+
user IP addresses, if you set `sendDefaultPii: true` in your `Sentry.init` options.
21+
22+
We apologize for any inconvenience caused!
23+
24+
## Fixes
25+
26+
- Ensure IP address is only inferred by Relay if `sendDefaultPii` is `true` ([#5138](https://github.com/getsentry/sentry-react-native/pull/5137))
27+
1128
### Dependencies
1229

1330
- Bump Bundler Plugins from v4.2.0 to v4.3.0 ([#5131](https://github.com/getsentry/sentry-react-native/pull/5131))

packages/core/src/js/client.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import type {
1313
import {
1414
_INTERNAL_flushLogsBuffer,
1515
addAutoIpAddressToSession,
16-
addAutoIpAddressToUser,
1716
Client,
1817
dateTimestampInSeconds,
1918
debug,
@@ -52,6 +51,15 @@ export class ReactNativeClient extends Client<ReactNativeClientOptions> {
5251
ignoreRequireCycleLogs(ReactNativeLibraries.ReactNativeVersion?.version);
5352
options._metadata = options._metadata || {};
5453
options._metadata.sdk = options._metadata.sdk || defaultSdkInfo;
54+
55+
// Only allow IP inferral by Relay if sendDefaultPii is true
56+
if (options._metadata?.sdk) {
57+
options._metadata.sdk.settings = {
58+
infer_ip: options.sendDefaultPii ? 'auto' : 'never',
59+
...options._metadata.sdk.settings,
60+
};
61+
}
62+
5563
// We default this to true, as it is the safer scenario
5664
options.parentSpanIsAlwaysRootSpan =
5765
options.parentSpanIsAlwaysRootSpan === undefined ? true : options.parentSpanIsAlwaysRootSpan;
@@ -60,7 +68,6 @@ export class ReactNativeClient extends Client<ReactNativeClientOptions> {
6068
this._outcomesBuffer = [];
6169

6270
if (options.sendDefaultPii === true) {
63-
this.on('postprocessEvent', addAutoIpAddressToUser);
6471
this.on('beforeSendSession', addAutoIpAddressToSession);
6572
}
6673

packages/core/test/client.test.ts

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -687,25 +687,42 @@ describe('Tests ReactNativeClient', () => {
687687
});
688688

689689
expect(mockTransportSend.mock.calls[0][firstArg][envelopeItems][0][envelopeItemPayload].user).toEqual(
690-
expect.objectContaining({ ip_address: '{{auto}}' }),
690+
expect.objectContaining({ ip_address: undefined }),
691+
);
692+
expect(mockTransportSend.mock.calls[0][firstArg][envelopeItems][0][envelopeItemPayload].sdk).toEqual(
693+
expect.objectContaining({
694+
settings: {
695+
infer_ip: 'never',
696+
},
697+
}),
691698
);
692699
});
693700

694-
test('adds ip_address {{auto}} to user if not set', () => {
701+
test('adds ip_address undefined to user if not set', () => {
695702
client.captureEvent({
696703
user: {},
697704
});
698705

699-
expect(mockTransportSend.mock.calls[0][firstArg][envelopeItems][0][envelopeItemPayload].user).toEqual(
700-
expect.objectContaining({ ip_address: '{{auto}}' }),
706+
expect(mockTransportSend.mock.calls[0][firstArg][envelopeItems][0][envelopeItemPayload].user).toBeEmptyObject();
707+
expect(mockTransportSend.mock.calls[0][firstArg][envelopeItems][0][envelopeItemPayload].sdk).toEqual(
708+
expect.objectContaining({
709+
settings: {
710+
infer_ip: 'never',
711+
},
712+
}),
701713
);
702714
});
703715

704-
test('adds ip_address {{auto}} to undefined user', () => {
716+
test('leaves ip_address undefined to undefined user', () => {
705717
client.captureEvent({});
706718

707-
expect(mockTransportSend.mock.calls[0][firstArg][envelopeItems][0][envelopeItemPayload].user).toEqual(
708-
expect.objectContaining({ ip_address: '{{auto}}' }),
719+
expect(mockTransportSend.mock.calls[0][firstArg][envelopeItems][0][envelopeItemPayload].user).toBeUndefined();
720+
expect(mockTransportSend.mock.calls[0][firstArg][envelopeItems][0][envelopeItemPayload].sdk).toEqual(
721+
expect.objectContaining({
722+
settings: {
723+
infer_ip: 'never',
724+
},
725+
}),
709726
);
710727
});
711728

@@ -724,15 +741,13 @@ describe('Tests ReactNativeClient', () => {
724741
expect(
725742
mockTransportSend.mock.calls[0][firstArg][envelopeItems][0][envelopeItemPayload].user?.ip_address,
726743
).toBeUndefined();
727-
});
728-
729-
test('uses ip address hooks if sendDefaultPii is true', () => {
730-
const { onSpy } = createClientWithSpy({
731-
sendDefaultPii: true,
732-
});
733-
734-
expect(onSpy).toHaveBeenCalledWith('postprocessEvent', addAutoIpAddressToUser);
735-
expect(onSpy).toHaveBeenCalledWith('beforeSendSession', addAutoIpAddressToSession);
744+
expect(mockTransportSend.mock.calls[0][firstArg][envelopeItems][0][envelopeItemPayload].sdk).toEqual(
745+
expect.objectContaining({
746+
settings: {
747+
infer_ip: 'never',
748+
},
749+
}),
750+
);
736751
});
737752

738753
test('does not add ip_address {{auto}} to session if sendDefaultPii is false', () => {

0 commit comments

Comments
 (0)