Skip to content
Open
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@
> make sure you follow our [migration guide](https://docs.sentry.io/platforms/react-native/migration/) first.
<!-- prettier-ignore-end -->

## Unreleased

### Fixes

- Fix user `geo` being dropped from the native scope by forwarding it as a structured object instead of a JSON string ([#6309](https://github.com/getsentry/sentry-react-native/pull/6309))

## 8.15.1

### Fixes
Expand Down
12 changes: 10 additions & 2 deletions packages/core/src/js/wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,8 @@ export const NATIVE: SentryNativeWrapper = {
}

// separate and serialize all non-default user keys.
let userKeys = null;
let userDataKeys = null;
let userKeys: { [key: string]: unknown } | null = null;
let userDataKeys: { [key: string]: string } | null = null;
if (user) {
const { id, ip_address, email, username, geo, ...otherKeys } = user;
const requiredUser: RequiredKeysUser = {
Expand All @@ -461,6 +461,14 @@ export const NATIVE: SentryNativeWrapper = {
geo,
};
userKeys = this._serializeObject(requiredUser);
// `geo` is a structured object that the native SDKs deserialize from a
// nested map. `_serializeObject` JSON-stringifies it like the scalar keys,
// which breaks native deserialization and drops the entire user, so
// overwrite it with the object. See
// https://github.com/getsentry/sentry-react-native/issues/6306
if (geo !== undefined) {
userKeys.geo = geo;
}
userDataKeys = this._serializeObject(otherKeys);
}

Expand Down
10 changes: 5 additions & 5 deletions packages/core/test/wrapper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -927,11 +927,11 @@ describe('Tests Native Wrapper', () => {
id: '123',
email: 'test@example.com',
username: 'testuser',
geo: JSON.stringify({
geo: {
city: 'San Francisco',
country_code: 'US',
region: 'California',
}),
},
},
{
customField: 'customValue',
Expand All @@ -951,10 +951,10 @@ describe('Tests Native Wrapper', () => {
expect(RNSentry.setUser).toHaveBeenCalledWith(
{
id: '123',
geo: JSON.stringify({
geo: {
city: 'New York',
country_code: 'US',
}),
},
},
{},
);
Expand All @@ -969,7 +969,7 @@ describe('Tests Native Wrapper', () => {
expect(RNSentry.setUser).toHaveBeenCalledWith(
{
id: '123',
geo: '{}',
geo: {},
},
{},
);
Expand Down
Loading