-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(browser): Export ipAddress helpers for use in other SDKs (#15079)
- Related to #15008 Export helpers to avoid duplications in sentry/react-native. - RN PR getsentry/sentry-react-native#4466
- Loading branch information
1 parent
e8c0260
commit 3c4df06
Showing
3 changed files
with
45 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import type { Session, SessionAggregates, User } from '../types-hoist'; | ||
|
||
// By default, we want to infer the IP address, unless this is explicitly set to `null` | ||
// We do this after all other processing is done | ||
// If `ip_address` is explicitly set to `null` or a value, we leave it as is | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export function addAutoIpAddressToUser(objWithMaybeUser: { user?: User | null }): void { | ||
if (objWithMaybeUser.user?.ip_address === undefined) { | ||
objWithMaybeUser.user = { | ||
...objWithMaybeUser.user, | ||
ip_address: '{{auto}}', | ||
}; | ||
} | ||
} | ||
|
||
/** | ||
* @internal | ||
*/ | ||
export function addAutoIpAddressToSession(session: Session | SessionAggregates): void { | ||
if ('aggregates' in session) { | ||
if (session.attrs?.['ip_address'] === undefined) { | ||
session.attrs = { | ||
...session.attrs, | ||
ip_address: '{{auto}}', | ||
}; | ||
} | ||
} else { | ||
if (session.ipAddress === undefined) { | ||
session.ipAddress = '{{auto}}'; | ||
} | ||
} | ||
} |