@@ -1350,7 +1350,9 @@ def test_limits_attribute_length_limits_code(self):
1350
1350
self .assertEqual (limits .max_span_attribute_length , 22 )
1351
1351
1352
1352
# global and span limits set to different values
1353
- limits = trace .SpanLimits (max_attribute_length = 22 , max_span_attribute_length = 33 )
1353
+ limits = trace .SpanLimits (
1354
+ max_attribute_length = 22 , max_span_attribute_length = 33
1355
+ )
1354
1356
self .assertEqual (limits .max_attribute_length , 22 )
1355
1357
self .assertEqual (limits .max_span_attribute_length , 33 )
1356
1358
@@ -1393,6 +1395,101 @@ def test_limits_values_env(self):
1393
1395
self .assertEqual (limits .max_events , max_events )
1394
1396
self .assertEqual (limits .max_links , max_links )
1395
1397
1398
+ def _test_span_limits (
1399
+ self , tracer , max_attrs , max_events , max_links , max_attr_len
1400
+ ):
1401
+ id_generator = RandomIdGenerator ()
1402
+ some_links = [
1403
+ trace_api .Link (
1404
+ trace_api .SpanContext (
1405
+ trace_id = id_generator .generate_trace_id (),
1406
+ span_id = id_generator .generate_span_id (),
1407
+ is_remote = False ,
1408
+ ),
1409
+ attributes = {"k" : self .long_val },
1410
+ )
1411
+ for _ in range (100 )
1412
+ ]
1413
+
1414
+ some_attrs = {
1415
+ "init_attribute_{}" .format (idx ): self .long_val
1416
+ for idx in range (100 )
1417
+ }
1418
+ with tracer .start_as_current_span (
1419
+ "root" , links = some_links , attributes = some_attrs
1420
+ ) as root :
1421
+ self .assertEqual (len (root .links ), max_links )
1422
+ self .assertEqual (len (root .attributes ), max_attrs )
1423
+ for idx in range (100 ):
1424
+ root .set_attribute (
1425
+ "my_str_attribute_{}" .format (idx ), self .long_val
1426
+ )
1427
+ root .set_attribute (
1428
+ "my_byte_attribute_{}" .format (idx ), self .long_val .encode ()
1429
+ )
1430
+ root .set_attribute (
1431
+ "my_int_attribute_{}" .format (idx ), self .long_val .encode ()
1432
+ )
1433
+ root .add_event (
1434
+ "my_event_{}" .format (idx ), attributes = {"k" : self .long_val }
1435
+ )
1436
+
1437
+ self .assertEqual (len (root .attributes ), max_attrs )
1438
+ self .assertEqual (len (root .events ), max_events )
1439
+
1440
+ for link in root .links :
1441
+ for attr_val in link .attributes .values ():
1442
+ self ._assert_attr_length (attr_val , max_attr_len )
1443
+
1444
+ for event in root .events :
1445
+ for attr_val in event .attributes .values ():
1446
+ self ._assert_attr_length (attr_val , max_attr_len )
1447
+
1448
+ for attr_val in root .attributes .values ():
1449
+ self ._assert_attr_length (attr_val , max_attr_len )
1450
+
1451
+ def _test_span_no_limits (self , tracer ):
1452
+ num_links = int (trace ._DEFAULT_OTEL_SPAN_LINK_COUNT_LIMIT ) + randint (
1453
+ 1 , 100
1454
+ )
1455
+
1456
+ id_generator = RandomIdGenerator ()
1457
+ some_links = [
1458
+ trace_api .Link (
1459
+ trace_api .SpanContext (
1460
+ trace_id = id_generator .generate_trace_id (),
1461
+ span_id = id_generator .generate_span_id (),
1462
+ is_remote = False ,
1463
+ )
1464
+ )
1465
+ for _ in range (num_links )
1466
+ ]
1467
+ with tracer .start_as_current_span ("root" , links = some_links ) as root :
1468
+ self .assertEqual (len (root .links ), num_links )
1469
+
1470
+ num_events = int (trace ._DEFAULT_OTEL_SPAN_EVENT_COUNT_LIMIT ) + randint (
1471
+ 1 , 100
1472
+ )
1473
+ with tracer .start_as_current_span ("root" ) as root :
1474
+ for idx in range (num_events ):
1475
+ root .add_event (
1476
+ "my_event_{}" .format (idx ), attributes = {"k" : self .long_val }
1477
+ )
1478
+
1479
+ self .assertEqual (len (root .events ), num_events )
1480
+
1481
+ num_attributes = int (
1482
+ trace ._DEFAULT_OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT
1483
+ ) + randint (1 , 100 )
1484
+ with tracer .start_as_current_span ("root" ) as root :
1485
+ for idx in range (num_attributes ):
1486
+ root .set_attribute (
1487
+ "my_attribute_{}" .format (idx ), self .long_val
1488
+ )
1489
+
1490
+ self .assertEqual (len (root .attributes ), num_attributes )
1491
+ for attr_val in root .attributes .values ():
1492
+ self .assertEqual (attr_val , self .long_val )
1396
1493
1397
1494
@mock .patch .dict (
1398
1495
"os.environ" ,
@@ -1469,7 +1566,6 @@ def test_span_limits_code(self):
1469
1566
OTEL_SPAN_ATTRIBUTE_VALUE_LENGTH_LIMIT : "unset" ,
1470
1567
},
1471
1568
)
1472
-
1473
1569
def test_span_no_limits_env (self ):
1474
1570
self ._test_span_no_limits (new_tracer ())
1475
1571
@@ -1495,7 +1591,13 @@ def test_dropped_attributes(self):
1495
1591
self .assertEqual (2 , span .resource .attributes .dropped )
1496
1592
1497
1593
def _test_span_limits (
1498
- self , tracer , max_attrs , max_events , max_links , max_attr_len , max_span_attr_len ,
1594
+ self ,
1595
+ tracer ,
1596
+ max_attrs ,
1597
+ max_events ,
1598
+ max_links ,
1599
+ max_attr_len ,
1600
+ max_span_attr_len ,
1499
1601
):
1500
1602
id_generator = RandomIdGenerator ()
1501
1603
some_links = [
@@ -1588,4 +1690,4 @@ def _test_span_no_limits(self, tracer):
1588
1690
1589
1691
self .assertEqual (len (root .attributes ), num_attributes )
1590
1692
for attr_val in root .attributes .values ():
1591
- self .assertEqual (attr_val , self .long_val )
1693
+ self .assertEqual (attr_val , self .long_val )
0 commit comments