@@ -8,12 +8,12 @@ import type {
8
8
ParameterizedString ,
9
9
Scope ,
10
10
SeverityLevel ,
11
- User ,
12
11
} from '@sentry/core' ;
13
12
import { Client , applySdkMetadata , getSDKSource } from '@sentry/core' ;
14
13
import { eventFromException , eventFromMessage } from './eventbuilder' ;
15
14
import { WINDOW } from './helpers' ;
16
15
import type { BrowserTransportOptions } from './transports/types' ;
16
+ import { addAutoIpAddressToSession , addAutoIpAddressToUser } from './utils/ipAddress' ;
17
17
18
18
/**
19
19
* Configuration options for the Sentry Browser SDK.
@@ -84,22 +84,8 @@ export class BrowserClient extends Client<BrowserClientOptions> {
84
84
} ) ;
85
85
}
86
86
87
- this . on ( 'postprocessEvent' , event => {
88
- addAutoIpAddressToUser ( event ) ;
89
- } ) ;
90
-
91
- this . on ( 'beforeSendSession' , session => {
92
- if ( 'aggregates' in session ) {
93
- if ( session . attrs ?. [ 'ip_address' ] === undefined ) {
94
- session . attrs = {
95
- ...session . attrs ,
96
- ip_address : '{{auto}}' ,
97
- } ;
98
- }
99
- } else {
100
- addAutoIpAddressToUser ( session ) ;
101
- }
102
- } ) ;
87
+ this . on ( 'postprocessEvent' , addAutoIpAddressToUser ) ;
88
+ this . on ( 'beforeSendSession' , addAutoIpAddressToSession ) ;
103
89
}
104
90
105
91
/**
@@ -134,15 +120,3 @@ export class BrowserClient extends Client<BrowserClientOptions> {
134
120
return super . _prepareEvent ( event , hint , currentScope , isolationScope ) ;
135
121
}
136
122
}
137
-
138
- // By default, we want to infer the IP address, unless this is explicitly set to `null`
139
- // We do this after all other processing is done
140
- // If `ip_address` is explicitly set to `null` or a value, we leave it as is
141
- function addAutoIpAddressToUser ( objWithMaybeUser : { user ?: User | null } ) : void {
142
- if ( objWithMaybeUser . user ?. ip_address === undefined ) {
143
- objWithMaybeUser . user = {
144
- ...objWithMaybeUser . user ,
145
- ip_address : '{{auto}}' ,
146
- } ;
147
- }
148
- }
0 commit comments