-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathipAddress.ts
34 lines (32 loc) · 1.05 KB
/
ipAddress.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import type { Session, SessionAggregates, User } from '@sentry/core';
/**
* @internal
* 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
*/
export function addAutoIpAddressToUser(objWithMaybeUser: { user?: User | null }): void {
if (objWithMaybeUser.user?.ip_address === undefined) {
objWithMaybeUser.user = {
...objWithMaybeUser.user,
ip_address: '{{auto}}',
};
}
}
/**
* @internal
* Adds the `ip_address` attribute to the session if it is not explicitly set to `null` or a value.
* @param session The session to add the `ip_address` attribute to.
*/
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 {
addAutoIpAddressToUser(session);
}
}