@@ -40,36 +40,57 @@ public override async Task EventBatchProcessingAsync(ICollection<EventContext> c
4040 if ( request == null )
4141 continue ;
4242
43- var info = await _parser . ParseAsync ( request . UserAgent , context . Project . Id ) . AnyContext ( ) ;
44- if ( info != null ) {
45- if ( ! String . Equals ( info . UserAgent . Family , "Other" ) ) {
46- request . Data [ RequestInfo . KnownDataKeys . Browser ] = info . UserAgent . Family ;
47- if ( ! String . IsNullOrEmpty ( info . UserAgent . Major ) ) {
48- request . Data [ RequestInfo . KnownDataKeys . BrowserVersion ] = String . Join ( "." , new [ ] { info . UserAgent . Major , info . UserAgent . Minor , info . UserAgent . Patch } . Where ( v => ! String . IsNullOrEmpty ( v ) ) ) ;
49- request . Data [ RequestInfo . KnownDataKeys . BrowserMajorVersion ] = info . UserAgent . Major ;
50- }
51- }
43+ AddClientIPAddress ( request , context . EventPostInfo ? . IpAddress ) ;
44+ await SetBrowserOsAndDeviceFromUserAgent ( request , context ) ;
45+
46+ context . Event . AddRequestInfo ( request . ApplyDataExclusions ( exclusions , MAX_VALUE_LENGTH ) ) ;
47+ }
48+ }
49+
50+ private void AddClientIPAddress ( RequestInfo request , string clientIPAddress ) {
51+ if ( String . IsNullOrEmpty ( clientIPAddress ) )
52+ return ;
53+
54+ if ( clientIPAddress . IsLocalHost ( ) )
55+ clientIPAddress = "127.0.0.1" ;
5256
53- if ( ! String . Equals ( info . Device . Family , "Other" ) )
54- request . Data [ RequestInfo . KnownDataKeys . Device ] = info . Device . Family ;
57+ var ips = ( request . ClientIpAddress ?? String . Empty )
58+ . Split ( new [ ] { ',' } , StringSplitOptions . RemoveEmptyEntries )
59+ . Select ( ip => ip . Trim ( ) )
60+ . Where ( ip => ! ip . IsLocalHost ( ) )
61+ . ToList ( ) ;
5562
63+ if ( ips . Count == 0 || ! clientIPAddress . IsLocalHost ( ) )
64+ ips . Add ( clientIPAddress ) ;
5665
57- if ( ! String . Equals ( info . OS . Family , "Other" ) ) {
58- request . Data [ RequestInfo . KnownDataKeys . OS ] = info . OS . Family ;
59- if ( ! String . IsNullOrEmpty ( info . OS . Major ) ) {
60- request . Data [ RequestInfo . KnownDataKeys . OSVersion ] = String . Join ( "." , new [ ] { info . OS . Major , info . OS . Minor , info . OS . Patch } . Where ( v => ! String . IsNullOrEmpty ( v ) ) ) ;
61- request . Data [ RequestInfo . KnownDataKeys . OSMajorVersion ] = info . OS . Major ;
62- }
66+ request . ClientIpAddress = ips . Distinct ( ) . ToDelimitedString ( ) ;
67+ }
68+
69+ private async Task SetBrowserOsAndDeviceFromUserAgent ( RequestInfo request , EventContext context ) {
70+ var info = await _parser . ParseAsync ( request . UserAgent , context . Project . Id ) . AnyContext ( ) ;
71+ if ( info != null ) {
72+ if ( ! String . Equals ( info . UserAgent . Family , "Other" ) ) {
73+ request . Data [ RequestInfo . KnownDataKeys . Browser ] = info . UserAgent . Family ;
74+ if ( ! String . IsNullOrEmpty ( info . UserAgent . Major ) ) {
75+ request . Data [ RequestInfo . KnownDataKeys . BrowserVersion ] = String . Join ( "." , new [ ] { info . UserAgent . Major , info . UserAgent . Minor , info . UserAgent . Patch } . Where ( v => ! String . IsNullOrEmpty ( v ) ) ) ;
76+ request . Data [ RequestInfo . KnownDataKeys . BrowserMajorVersion ] = info . UserAgent . Major ;
6377 }
78+ }
6479
65- var botPatterns = context . Project . Configuration . Settings . ContainsKey ( SettingsDictionary . KnownKeys . UserAgentBotPatterns )
66- ? context . Project . Configuration . Settings . GetStringCollection ( SettingsDictionary . KnownKeys . UserAgentBotPatterns ) . ToList ( )
67- : new List < string > ( ) ;
80+ if ( ! String . Equals ( info . Device . Family , "Other" ) )
81+ request . Data [ RequestInfo . KnownDataKeys . Device ] = info . Device . Family ;
6882
69- request . Data [ RequestInfo . KnownDataKeys . IsBot ] = info . Device . IsSpider || request . UserAgent . AnyWildcardMatches ( botPatterns ) ;
83+ if ( ! String . Equals ( info . OS . Family , "Other" ) ) {
84+ request . Data [ RequestInfo . KnownDataKeys . OS ] = info . OS . Family ;
85+ if ( ! String . IsNullOrEmpty ( info . OS . Major ) ) {
86+ request . Data [ RequestInfo . KnownDataKeys . OSVersion ] = String . Join ( "." , new [ ] { info . OS . Major , info . OS . Minor , info . OS . Patch } . Where ( v => ! String . IsNullOrEmpty ( v ) ) ) ;
87+ request . Data [ RequestInfo . KnownDataKeys . OSMajorVersion ] = info . OS . Major ;
88+ }
7089 }
7190
72- context . Event . AddRequestInfo ( request . ApplyDataExclusions ( exclusions , MAX_VALUE_LENGTH ) ) ;
91+ var botPatterns = context . Project . Configuration . Settings . ContainsKey ( SettingsDictionary . KnownKeys . UserAgentBotPatterns ) ? context . Project . Configuration . Settings . GetStringCollection ( SettingsDictionary . KnownKeys . UserAgentBotPatterns ) . ToList ( ) : new List < string > ( ) ;
92+
93+ request . Data [ RequestInfo . KnownDataKeys . IsBot ] = info . Device . IsSpider || request . UserAgent . AnyWildcardMatches ( botPatterns ) ;
7394 }
7495 }
7596 }
0 commit comments