@@ -205,14 +205,8 @@ public void AddCommonProperty(string key, string value)
205205 {
206206 return ;
207207 }
208- if ( ! checkLength ( key ) )
208+ if ( ! checkKeyValueLength ( key , value ) )
209209 {
210- TapLog . Error ( key + " Property key length should be less than or equal to 256 characters." ) ;
211- return ;
212- }
213- if ( ! checkLength ( value ) )
214- {
215- TapLog . Error ( value + " Property value length should be less than or equal to 256 characters." ) ;
216210 return ;
217211 }
218212 Tracker . AddCommonProperty ( key , value ) ;
@@ -351,9 +345,8 @@ public Dictionary<string, object> GetDynamicProperties()
351345 }
352346 }
353347
354- private bool checkLength ( string value )
348+ private bool checkLength ( string value , int maxLength = 256 )
355349 {
356- var maxLength = 256 ;
357350 if ( value . Length <= 0 || value . Length > maxLength )
358351 {
359352 return false ;
@@ -400,20 +393,39 @@ private Dictionary<string, object> filterProperties(Dictionary<string, object> p
400393 {
401394 foreach ( var property in properties )
402395 {
403- if ( property . Key . Length <= 0 || property . Key . Length > 256 )
404- {
405- TapLog . Log ( property . Key + " Property key length should be more then 0 and less than or equal to 256 characters." ) ;
406- continue ;
407- }
408- if ( property . Value . ToString ( ) . Length > 256 )
396+ if ( ! checkKeyValueLength ( property . Key , property . Value ) )
409397 {
410- TapLog . Log ( property . Value + " Property value length should be less than or equal to 256 characters." ) ;
411398 continue ;
412399 }
413400 filteredProperties . Add ( property . Key , property . Value ) ;
414401 }
415402 }
416403 return filteredProperties ;
417404 }
405+
406+ private bool checkKeyValueLength ( string key , object value )
407+ {
408+
409+ if ( key == null || key . Length <= 0 || key . Length > 256 )
410+ {
411+ TapLog . Log ( key + " Property key length should be more then 0 and less than or equal to 256 characters." ) ;
412+ return false ;
413+ }
414+ var maxLength = 4096 ;
415+ if ( key . Equals ( "device_id" ) || key . Equals ( "user_id" ) )
416+ {
417+ maxLength = 256 ;
418+ }
419+ if ( value is string stringValue )
420+ {
421+ if ( stringValue . Length > maxLength )
422+ {
423+ TapLog . Log ( key + " Property value length should be less than or equal to " + maxLength + " characters." ) ;
424+ return false ;
425+ }
426+ }
427+ return true ;
428+ }
429+
418430 }
419431}
0 commit comments