@@ -487,39 +487,61 @@ def test_invalid_attribute_values(self):
487
487
488
488
self .assertEqual (len (root .attributes ), 0 )
489
489
490
- def test_check_sequence_helper (self ):
490
+ def test_check_attribute_helper (self ):
491
491
# pylint: disable=protected-access
492
492
self .assertEqual (
493
- trace .Span ._check_attribute_value_sequence ([1 , 2 , 3.4 , "ss" , 4 ]),
494
- "different type " ,
493
+ trace .Span ._check_attribute_value ([1 , 2 , 3.4 , "ss" , 4 ]),
494
+ "different types in attribute value sequence " ,
495
495
)
496
496
self .assertEqual (
497
- trace .Span ._check_attribute_value_sequence ([dict (), 1 , 2 , 3.4 , 4 ]),
498
- "invalid type" ,
497
+ trace .Span ._check_attribute_value ([dict (), 1 , 2 , 3.4 , 4 ]),
498
+ "invalid type in attribute value sequence " ,
499
499
)
500
500
self .assertEqual (
501
- trace .Span ._check_attribute_value_sequence (
501
+ trace .Span ._check_attribute_value (
502
502
["sw" , "lf" , 3.4 , "ss" ]
503
503
),
504
- "different type " ,
504
+ "different types in attribute value sequence " ,
505
505
)
506
506
self .assertEqual (
507
- trace .Span ._check_attribute_value_sequence ([1 , 2 , 3.4 , 5 ]),
508
- "different type " ,
507
+ trace .Span ._check_attribute_value ([1 , 2 , 3.4 , 5 ]),
508
+ "different types in attribute value sequence " ,
509
509
)
510
510
self .assertIsNone (
511
- trace .Span ._check_attribute_value_sequence ([1 , 2 , 3 , 5 ])
511
+ trace .Span ._check_attribute_value ([1 , 2 , 3 , 5 ])
512
512
)
513
513
self .assertIsNone (
514
- trace .Span ._check_attribute_value_sequence ([1.2 , 2.3 , 3.4 , 4.5 ])
514
+ trace .Span ._check_attribute_value ([1.2 , 2.3 , 3.4 , 4.5 ])
515
515
)
516
516
self .assertIsNone (
517
- trace .Span ._check_attribute_value_sequence ([True , False ])
517
+ trace .Span ._check_attribute_value ([True , False ])
518
518
)
519
519
self .assertIsNone (
520
- trace .Span ._check_attribute_value_sequence (["ss" , "dw" , "fw" ])
520
+ trace .Span ._check_attribute_value (["ss" , "dw" , "fw" ])
521
+ )
522
+ self .assertIsNone (
523
+ trace .Span ._check_attribute_value ([])
524
+ )
525
+
526
+
527
+ self .assertEqual (
528
+ trace .Span ._check_attribute_value (dict ()),
529
+ "invalid type for attribute value" ,
530
+ )
531
+ self .assertIsNone (
532
+ trace .Span ._check_attribute_value (True )
533
+ )
534
+ self .assertIsNone (
535
+ trace .Span ._check_attribute_value ('hi' )
536
+ )
537
+ self .assertIsNone (
538
+ trace .Span ._check_attribute_value (3.4 )
539
+ )
540
+ self .assertIsNone (
541
+ trace .Span ._check_attribute_value (15 )
521
542
)
522
543
544
+
523
545
def test_sampling_attributes (self ):
524
546
decision_attributes = {
525
547
"sampler-attr" : "sample-val" ,
@@ -561,33 +583,52 @@ def test_events(self):
561
583
562
584
# event name and attributes
563
585
now = time_ns ()
564
- root .add_event ("event1" , {"name" : "pluto" })
586
+ root .add_event ("event1" , {"name" : "pluto" , "some_bools" : [ True , False ] })
565
587
566
588
# event name, attributes and timestamp
567
589
now = time_ns ()
568
- root .add_event ("event2" , {"name" : "birthday" }, now )
590
+ root .add_event ("event2" , {"name" : ["birthday" ]}, now )
591
+
592
+ mutable_list = ["original_contents" ]
593
+ root .add_event ("event3" , {"name" : mutable_list })
569
594
570
595
def event_formatter ():
571
596
return {"name" : "hello" }
572
597
573
598
# lazy event
574
- root .add_lazy_event ("event3 " , event_formatter , now )
599
+ root .add_lazy_event ("event4 " , event_formatter , now )
575
600
576
- self .assertEqual (len (root .events ), 4 )
601
+ self .assertEqual (len (root .events ), 5 )
577
602
578
603
self .assertEqual (root .events [0 ].name , "event0" )
579
604
self .assertEqual (root .events [0 ].attributes , {})
580
605
581
606
self .assertEqual (root .events [1 ].name , "event1" )
582
- self .assertEqual (root .events [1 ].attributes , {"name" : "pluto" })
607
+ self .assertEqual (root .events [1 ].attributes , {"name" : "pluto" , "some_bools" : ( True , False ) })
583
608
584
609
self .assertEqual (root .events [2 ].name , "event2" )
585
- self .assertEqual (root .events [2 ].attributes , {"name" : "birthday" })
610
+ self .assertEqual (root .events [2 ].attributes , {"name" : ( "birthday" ,) })
586
611
self .assertEqual (root .events [2 ].timestamp , now )
587
612
588
613
self .assertEqual (root .events [3 ].name , "event3" )
589
- self .assertEqual (root .events [3 ].attributes , {"name" : "hello" })
590
- self .assertEqual (root .events [3 ].timestamp , now )
614
+ self .assertEqual (root .events [3 ].attributes , {"name" : ("original_contents" ,)})
615
+ mutable_list = ["new_contents" ]
616
+ self .assertEqual (root .events [3 ].attributes , {"name" : ("original_contents" ,)})
617
+
618
+ self .assertEqual (root .events [4 ].name , "event4" )
619
+ self .assertEqual (root .events [4 ].attributes , {"name" : "hello" })
620
+ self .assertEqual (root .events [4 ].timestamp , now )
621
+
622
+ def test_invalid_event_attributes (self ):
623
+ self .assertIsNone (self .tracer .get_current_span ())
624
+
625
+ with self .tracer .start_as_current_span ("root" ) as root :
626
+ root .add_event ("event0" , {"attr1" : True , "attr2" : ['hi' , False ]})
627
+ root .add_event ("event0" , {"attr1" : dict ()})
628
+ root .add_event ("event0" , {"attr1" : [[True ]]})
629
+ root .add_event ("event0" , {"attr1" : [dict ()]})
630
+
631
+ self .assertEqual (len (root .events ), 0 )
591
632
592
633
def test_links (self ):
593
634
other_context1 = trace_api .SpanContext (
@@ -882,3 +923,4 @@ def test_add_span_processor_after_span_creation(self):
882
923
expected_list .append (span_event_end_fmt ("SP1" , "foo" ))
883
924
884
925
self .assertListEqual (spans_calls_list , expected_list )
926
+
0 commit comments