@@ -368,7 +368,11 @@ def test_attributes(self):
368
368
root .set_attribute ("attr-key" , "attr-value1" )
369
369
root .set_attribute ("attr-key" , "attr-value2" )
370
370
371
- self .assertEqual (len (root .attributes ), 7 )
371
+ root .set_attribute ("empty-list" , [])
372
+ root .set_attribute ("list-of-bools" , [True , True , False ])
373
+ root .set_attribute ("list-of-numerics" , [123 , 3.14 , 0 ])
374
+
375
+ self .assertEqual (len (root .attributes ), 10 )
372
376
self .assertEqual (root .attributes ["component" ], "http" )
373
377
self .assertEqual (root .attributes ["http.method" ], "GET" )
374
378
self .assertEqual (
@@ -379,6 +383,13 @@ def test_attributes(self):
379
383
self .assertEqual (root .attributes ["http.status_text" ], "OK" )
380
384
self .assertEqual (root .attributes ["misc.pi" ], 3.14 )
381
385
self .assertEqual (root .attributes ["attr-key" ], "attr-value2" )
386
+ self .assertEqual (root .attributes ["empty-list" ], [])
387
+ self .assertEqual (
388
+ root .attributes ["list-of-bools" ], [True , True , False ]
389
+ )
390
+ self .assertEqual (
391
+ root .attributes ["list-of-numerics" ], [123 , 3.14 , 0 ]
392
+ )
382
393
383
394
attributes = {
384
395
"attr-key" : "val" ,
@@ -393,6 +404,46 @@ def test_attributes(self):
393
404
self .assertEqual (root .attributes ["attr-key2" ], "val2" )
394
405
self .assertEqual (root .attributes ["attr-in-both" ], "span-attr" )
395
406
407
+ def test_invalid_attribute_values (self ):
408
+ with self .tracer .start_as_current_span ("root" ) as root :
409
+ root .set_attribute ("non-primitive-data-type" , dict ())
410
+ root .set_attribute (
411
+ "list-of-mixed-data-types-numeric-first" ,
412
+ [123 , False , "string" ],
413
+ )
414
+ root .set_attribute (
415
+ "list-of-mixed-data-types-non-numeric-first" ,
416
+ [False , 123 , "string" ],
417
+ )
418
+ root .set_attribute (
419
+ "list-with-non-primitive-data-type" , [dict (), 123 ]
420
+ )
421
+
422
+ self .assertEqual (len (root .attributes ), 0 )
423
+
424
+ def test_check_sequence_helper (self ):
425
+ # pylint: disable=protected-access
426
+ self .assertEqual (
427
+ trace .Span ._check_attribute_value_sequence ([1 , 2 , 3.4 , "ss" , 4 ]),
428
+ "different type" ,
429
+ )
430
+ self .assertEqual (
431
+ trace .Span ._check_attribute_value_sequence ([dict (), 1 , 2 , 3.4 , 4 ]),
432
+ "invalid type" ,
433
+ )
434
+ self .assertEqual (
435
+ trace .Span ._check_attribute_value_sequence (
436
+ ["sw" , "lf" , 3.4 , "ss" ]
437
+ ),
438
+ "different type" ,
439
+ )
440
+ self .assertIsNone (
441
+ trace .Span ._check_attribute_value_sequence ([1 , 2 , 3.4 , 5 ])
442
+ )
443
+ self .assertIsNone (
444
+ trace .Span ._check_attribute_value_sequence (["ss" , "dw" , "fw" ])
445
+ )
446
+
396
447
def test_sampling_attributes (self ):
397
448
decision_attributes = {
398
449
"sampler-attr" : "sample-val" ,
0 commit comments