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
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,23 @@

## Unreleased

### Important Changes

This release includes a fix for a [behaviour change](https://docs.sentry.io/platforms/javascript/migration/v8-to-v9/#behavior-changes)
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,
if `sendDefaultPii` was set to `true`.

To avoid making a major bump, the fix was patched on the current version and not by bumping to V8.
There is _no API_ breakage involved and hence it is safe to update.
However, after updating the SDK, events (errors, traces, replays, etc.) sent from the browser, will only include
user IP addresses, if you set `sendDefaultPii: true` in your `Sentry.init` options.

We apologize for any inconvenience caused!

## Fixes

- Ensure IP address is only inferred by Relay if `sendDefaultPii` is `true` ([#5138](https://github.com/getsentry/sentry-react-native/pull/5137))

### Dependencies

- Bump Bundler Plugins from v4.2.0 to v4.3.0 ([#5131](https://github.com/getsentry/sentry-react-native/pull/5131))
Expand Down
11 changes: 9 additions & 2 deletions packages/core/src/js/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import type {
import {
_INTERNAL_flushLogsBuffer,
addAutoIpAddressToSession,
addAutoIpAddressToUser,
Client,
dateTimestampInSeconds,
debug,
Expand Down Expand Up @@ -52,6 +51,15 @@ export class ReactNativeClient extends Client<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,
};
}

// We default this to true, as it is the safer scenario
options.parentSpanIsAlwaysRootSpan =
options.parentSpanIsAlwaysRootSpan === undefined ? true : options.parentSpanIsAlwaysRootSpan;
Expand All @@ -60,7 +68,6 @@ export class ReactNativeClient extends Client<ReactNativeClientOptions> {
this._outcomesBuffer = [];

if (options.sendDefaultPii === true) {
this.on('postprocessEvent', addAutoIpAddressToUser);
this.on('beforeSendSession', addAutoIpAddressToSession);
}

Expand Down
47 changes: 31 additions & 16 deletions packages/core/test/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -687,25 +687,42 @@ describe('Tests ReactNativeClient', () => {
});

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

test('adds ip_address {{auto}} to user if not set', () => {
test('adds ip_address undefined to user if not set', () => {
client.captureEvent({
user: {},
});

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

test('adds ip_address {{auto}} to undefined user', () => {
test('leaves ip_address undefined to undefined user', () => {
client.captureEvent({});

expect(mockTransportSend.mock.calls[0][firstArg][envelopeItems][0][envelopeItemPayload].user).toEqual(
expect.objectContaining({ ip_address: '{{auto}}' }),
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',
},
}),
);
});

Expand All @@ -724,15 +741,13 @@ describe('Tests ReactNativeClient', () => {
expect(
mockTransportSend.mock.calls[0][firstArg][envelopeItems][0][envelopeItemPayload].user?.ip_address,
).toBeUndefined();
});

test('uses ip address hooks if sendDefaultPii is true', () => {
const { onSpy } = createClientWithSpy({
sendDefaultPii: true,
});

expect(onSpy).toHaveBeenCalledWith('postprocessEvent', addAutoIpAddressToUser);
expect(onSpy).toHaveBeenCalledWith('beforeSendSession', addAutoIpAddressToSession);
expect(mockTransportSend.mock.calls[0][firstArg][envelopeItems][0][envelopeItemPayload].sdk).toEqual(
expect.objectContaining({
settings: {
infer_ip: 'never',
},
}),
);
});

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