67
67
_DEFAULT_OTEL_LINK_ATTRIBUTE_COUNT_LIMIT = 128
68
68
69
69
70
- _ENV_VALUE_UNSET = "unset "
70
+ _ENV_VALUE_UNSET = ""
71
71
72
72
# pylint: disable=protected-access
73
73
_TRACE_SAMPLER = sampling ._get_from_env_or_default ()
@@ -533,7 +533,7 @@ class SpanLimits:
533
533
- All limit arguments are optional.
534
534
- If a limit argument is not set, the class will try to read its value from the corresponding
535
535
environment variable.
536
- - If the environment variable is not set, the default value for the limit is used.
536
+ - If the environment variable is not set, the default value, if any, will be used.
537
537
538
538
Args:
539
539
max_attributes: Maximum number of attributes that can be added to a Span.
@@ -553,7 +553,7 @@ class SpanLimits:
553
553
the specified length will be truncated.
554
554
"""
555
555
556
- UNSET = - 1
556
+ UNSET = "unset"
557
557
558
558
def __init__ (
559
559
self ,
@@ -609,15 +609,18 @@ def __repr__(self):
609
609
def _from_env_if_absent (
610
610
cls , value : Optional [int ], env_var : str , default : Optional [int ] = None
611
611
) -> Optional [int ]:
612
- if value is cls .UNSET :
612
+ if value == cls .UNSET :
613
613
return None
614
614
615
615
err_msg = "{0} must be a non-negative integer but got {}"
616
616
617
+ # if no value is provided for the limit, try to load it from env
617
618
if value is None :
618
- str_value = environ . get ( env_var , "" ). strip (). lower ()
619
- if not str_value :
619
+ # return default value if env var is not set
620
+ if env_var not in environ :
620
621
return default
622
+
623
+ str_value = environ .get (env_var , "" ).strip ().lower ()
621
624
if str_value == _ENV_VALUE_UNSET :
622
625
return None
623
626
0 commit comments