@@ -8,12 +8,12 @@ import type {
88 ParameterizedString ,
99 Scope ,
1010 SeverityLevel ,
11- User ,
1211} from '@sentry/core' ;
1312import { Client , applySdkMetadata , getSDKSource } from '@sentry/core' ;
1413import { eventFromException , eventFromMessage } from './eventbuilder' ;
1514import { WINDOW } from './helpers' ;
1615import type { BrowserTransportOptions } from './transports/types' ;
16+ import { addAutoIpAddressToSession , addAutoIpAddressToUser } from './utils/ipAddress' ;
1717
1818/**
1919 * Configuration options for the Sentry Browser SDK.
@@ -84,22 +84,8 @@ export class BrowserClient extends Client<BrowserClientOptions> {
8484 } ) ;
8585 }
8686
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 ) ;
10389 }
10490
10591 /**
@@ -134,15 +120,3 @@ export class BrowserClient extends Client<BrowserClientOptions> {
134120 return super . _prepareEvent ( event , hint , currentScope , isolationScope ) ;
135121 }
136122}
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