@@ -248,30 +248,16 @@ def __init__(
248
248
if attributes is None :
249
249
self .attributes = Span ._empty_attributes
250
250
else :
251
- self .attributes = BoundedDict (MAX_NUM_ATTRIBUTES )
252
- for attr_key , attr_value in attributes .items ():
253
- error_message = self ._check_attribute_value (attr_value )
254
- if error_message :
255
- logger .warning (error_message )
256
- else :
257
- self .attributes [attr_key ] = attr_value
251
+ self ._filter_attribute_values (attributes )
252
+ self .attributes = BoundedDict .from_map (MAX_NUM_ATTRIBUTES , attributes )
258
253
259
254
if events is None :
260
255
self .events = Span ._empty_events
261
256
else :
262
257
self .events = BoundedList (MAX_NUM_EVENTS )
263
258
for event in events :
264
- good_event = True
265
- for attr_key , attr_value in list (event .attributes .items ()):
266
- error_message = self ._check_attribute_value (attr_value )
267
- if error_message :
268
- logger .warning (error_message )
269
- good_event = False
270
- break
271
- if isinstance (attr_value , MutableSequence ):
272
- attributes [attr_key ] = tuple (attr_value )
273
- if good_event :
274
- self .events .append (event )
259
+ self ._filter_attribute_values (event .attributes )
260
+ self .events .append (event )
275
261
276
262
if links is None :
277
263
self .links = Span ._empty_links
@@ -428,6 +414,17 @@ def _check_attribute_value(value: types.AttributeValue) -> Optional[str]:
428
414
[valid_type .__name__ for valid_type in valid_types ],
429
415
)
430
416
417
+ def _filter_attribute_values (self , attributes : types .Attributes ):
418
+ for attr_key , attr_value in list (attributes .items ()):
419
+ error_message = self ._check_attribute_value (attr_value )
420
+ if error_message :
421
+ attributes .pop (attr_key )
422
+ logger .warning (error_message )
423
+ elif isinstance (attr_value , MutableSequence ):
424
+ attributes [attr_key ] = tuple (attr_value )
425
+ else :
426
+ attributes [attr_key ] = attr_value
427
+
431
428
def _add_event (self , event : EventBase ) -> None :
432
429
with self ._lock :
433
430
if not self .is_recording_events ():
@@ -450,13 +447,7 @@ def add_event(
450
447
if attributes is None :
451
448
attributes = Span ._empty_attributes
452
449
else :
453
- for attr_key , attr_value in list (attributes .items ()):
454
- error_message = self ._check_attribute_value (attr_value )
455
- if error_message :
456
- logger .warning (error_message )
457
- return
458
- if isinstance (attr_value , MutableSequence ):
459
- attributes [attr_key ] = tuple (attr_value )
450
+ self ._filter_attribute_values (attributes )
460
451
self ._add_event (
461
452
Event (
462
453
name = name ,
0 commit comments