41
41
from opentelemetry .attributes import BoundedAttributes
42
42
from opentelemetry .sdk import util
43
43
from opentelemetry .sdk .environment_variables import (
44
+ OTEL_ATTRIBUTE_COUNT_LIMIT ,
44
45
OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT ,
45
46
OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT ,
46
47
OTEL_LINK_ATTRIBUTE_COUNT_LIMIT ,
61
62
62
63
logger = logging .getLogger (__name__ )
63
64
65
+ _DEFAULT_OTEL_ATTRIBUTE_COUNT_LIMIT = 128
64
66
_DEFAULT_OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT = 128
65
- _DEFAULT_OTEL_SPAN_EVENT_COUNT_LIMIT = 128
66
- _DEFAULT_OTEL_SPAN_LINK_COUNT_LIMIT = 128
67
67
_DEFAULT_OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT = 128
68
68
_DEFAULT_OTEL_LINK_ATTRIBUTE_COUNT_LIMIT = 128
69
+ _DEFAULT_OTEL_SPAN_EVENT_COUNT_LIMIT = 128
70
+ _DEFAULT_OTEL_SPAN_LINK_COUNT_LIMIT = 128
69
71
70
72
71
73
_ENV_VALUE_UNSET = ""
@@ -533,19 +535,23 @@ class SpanLimits:
533
535
Limit precedence:
534
536
535
537
- If a model specific limit is set, it will be used.
538
+ - Else if the corresponding global limit is set, it will be used.
536
539
- Else if the model specific limit has a default value, the default value will be used.
537
- - Else if model specific limit has a corresponding global limit , the global limit will be used.
540
+ - Else if the global limit has a default value , the default value will be used.
538
541
539
542
Args:
540
- max_attributes: Maximum number of attributes that can be added to a Span .
541
- Environment variable: OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT
542
- Default: {_DEFAULT_SPAN_ATTRIBUTE_COUNT_LIMIT }
543
+ max_attributes: Maximum number of attributes that can be added to a span, event, and link .
544
+ Environment variable: OTEL_ATTRIBUTE_COUNT_LIMIT
545
+ Default: {_DEFAULT_ATTRIBUTE_COUNT_LIMIT }
543
546
max_events: Maximum number of events that can be added to a Span.
544
547
Environment variable: OTEL_SPAN_EVENT_COUNT_LIMIT
545
548
Default: {_DEFAULT_SPAN_EVENT_COUNT_LIMIT}
546
549
max_links: Maximum number of links that can be added to a Span.
547
550
Environment variable: OTEL_SPAN_LINK_COUNT_LIMIT
548
551
Default: {_DEFAULT_SPAN_LINK_COUNT_LIMIT}
552
+ max_span_attributes: Maximum number of attributes that can be added to a Span.
553
+ Environment variable: OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT
554
+ Default: {_DEFAULT_OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT}
549
555
max_event_attributes: Maximum number of attributes that can be added to an Event.
550
556
Default: {_DEFAULT_OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT}
551
557
max_link_attributes: Maximum number of attributes that can be added to a Link.
@@ -563,16 +569,14 @@ def __init__(
563
569
max_attributes : Optional [int ] = None ,
564
570
max_events : Optional [int ] = None ,
565
571
max_links : Optional [int ] = None ,
572
+ max_span_attributes : Optional [int ] = None ,
566
573
max_event_attributes : Optional [int ] = None ,
567
574
max_link_attributes : Optional [int ] = None ,
568
575
max_attribute_length : Optional [int ] = None ,
569
576
max_span_attribute_length : Optional [int ] = None ,
570
577
):
571
- self .max_attributes = self ._from_env_if_absent (
572
- max_attributes ,
573
- OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT ,
574
- _DEFAULT_OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT ,
575
- )
578
+
579
+ # span events and links count
576
580
self .max_events = self ._from_env_if_absent (
577
581
max_events ,
578
582
OTEL_SPAN_EVENT_COUNT_LIMIT ,
@@ -583,17 +587,32 @@ def __init__(
583
587
OTEL_SPAN_LINK_COUNT_LIMIT ,
584
588
_DEFAULT_OTEL_SPAN_LINK_COUNT_LIMIT ,
585
589
)
590
+
591
+ # attribute count
592
+ global_max_attributes = self ._from_env_if_absent (
593
+ max_attributes , OTEL_ATTRIBUTE_COUNT_LIMIT
594
+ )
595
+ self .max_attributes = (
596
+ global_max_attributes or _DEFAULT_OTEL_ATTRIBUTE_COUNT_LIMIT
597
+ )
598
+
599
+ self .max_span_attributes = self ._from_env_if_absent (
600
+ max_span_attributes ,
601
+ OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT ,
602
+ global_max_attributes or _DEFAULT_OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT ,
603
+ )
586
604
self .max_event_attributes = self ._from_env_if_absent (
587
605
max_event_attributes ,
588
606
OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT ,
589
- _DEFAULT_OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT ,
607
+ global_max_attributes or _DEFAULT_OTEL_EVENT_ATTRIBUTE_COUNT_LIMIT ,
590
608
)
591
609
self .max_link_attributes = self ._from_env_if_absent (
592
610
max_link_attributes ,
593
611
OTEL_LINK_ATTRIBUTE_COUNT_LIMIT ,
594
- _DEFAULT_OTEL_LINK_ATTRIBUTE_COUNT_LIMIT ,
612
+ global_max_attributes or _DEFAULT_OTEL_LINK_ATTRIBUTE_COUNT_LIMIT ,
595
613
)
596
614
615
+ # attribute length
597
616
self .max_attribute_length = self ._from_env_if_absent (
598
617
max_attribute_length ,
599
618
OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT ,
@@ -606,7 +625,7 @@ def __init__(
606
625
)
607
626
608
627
def __repr__ (self ):
609
- return f"{ type (self ).__name__ } (max_span_attributes={ self .max_span_attribute_length } , max_events_attributes={ self .max_event_attributes } , max_link_attributes={ self .max_link_attributes } , max_attributes={ self .max_attributes } , max_events={ self .max_events } , max_links={ self .max_links } , max_attribute_length={ self .max_attribute_length } )"
628
+ return f"{ type (self ).__name__ } (max_span_attributes={ self .max_span_attributes } , max_events_attributes={ self .max_event_attributes } , max_link_attributes={ self .max_link_attributes } , max_attributes={ self .max_attributes } , max_events={ self .max_events } , max_links={ self .max_links } , max_attribute_length={ self .max_attribute_length } )"
610
629
611
630
@classmethod
612
631
def _from_env_if_absent (
@@ -641,13 +660,14 @@ def _from_env_if_absent(
641
660
max_attributes = SpanLimits .UNSET ,
642
661
max_events = SpanLimits .UNSET ,
643
662
max_links = SpanLimits .UNSET ,
663
+ max_span_attributes = SpanLimits .UNSET ,
644
664
max_event_attributes = SpanLimits .UNSET ,
645
665
max_link_attributes = SpanLimits .UNSET ,
646
666
max_attribute_length = SpanLimits .UNSET ,
647
667
max_span_attribute_length = SpanLimits .UNSET ,
648
668
)
649
669
650
- # not remove for backward compat. please use SpanLimits instead.
670
+ # not removed for backward compat. please use SpanLimits instead.
651
671
SPAN_ATTRIBUTE_COUNT_LIMIT = SpanLimits ._from_env_if_absent (
652
672
None ,
653
673
OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT ,
@@ -717,7 +737,7 @@ def __init__(
717
737
self ._limits = limits
718
738
self ._lock = threading .Lock ()
719
739
self ._attributes = BoundedAttributes (
720
- self ._limits .max_attributes ,
740
+ self ._limits .max_span_attributes ,
721
741
attributes ,
722
742
immutable = False ,
723
743
max_value_len = self ._limits .max_span_attribute_length ,
0 commit comments