-
Notifications
You must be signed in to change notification settings - Fork 657
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix limit env vars unset/unlimited values #2054
Changes from 6 commits
061e72c
18574c4
90b361a
697846f
fdd4610
1ca4c52
303ed43
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -67,7 +67,7 @@ | |
_DEFAULT_OTEL_LINK_ATTRIBUTE_COUNT_LIMIT = 128 | ||
|
||
|
||
_ENV_VALUE_UNSET = "unset" | ||
_ENV_VALUE_UNSET = "" | ||
|
||
# pylint: disable=protected-access | ||
_TRACE_SAMPLER = sampling._get_from_env_or_default() | ||
|
@@ -533,7 +533,7 @@ class SpanLimits: | |
- All limit arguments are optional. | ||
- If a limit argument is not set, the class will try to read its value from the corresponding | ||
environment variable. | ||
- If the environment variable is not set, the default value for the limit is used. | ||
- If the environment variable is not set, the default value, if any, will be used. | ||
|
||
Args: | ||
max_attributes: Maximum number of attributes that can be added to a Span. | ||
|
@@ -609,15 +609,18 @@ def __repr__(self): | |
def _from_env_if_absent( | ||
cls, value: Optional[int], env_var: str, default: Optional[int] = None | ||
) -> Optional[int]: | ||
if value is cls.UNSET: | ||
if value == cls.UNSET: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe I'm not fully understanding this scenario. When will There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The API usage looks like the following in order to not set a limit: SpanLimits(max_attributes=SpanLimits.UNSET) SpanLimits.UNSET is a symbol that users can pass as a limit to set the limit to infinity. We can freely change its internal value to anything without breaking any contracts. The reason why I used "unset" was that I thought -1 might be confusing as the spec disallows it for env vars. Internally we can still use -1 as the symbol value. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed it back to -1 as this is probably causing more confusion and does not respect the function contract. I wonder why mypy didn't catch it. |
||
return None | ||
|
||
err_msg = "{0} must be a non-negative integer but got {}" | ||
|
||
# if no value is provided for the limit, try to load it from env | ||
if value is None: | ||
str_value = environ.get(env_var, "").strip().lower() | ||
if not str_value: | ||
# return default value if env var is not set | ||
if env_var not in environ: | ||
return default | ||
|
||
str_value = environ.get(env_var, "").strip().lower() | ||
if str_value == _ENV_VALUE_UNSET: | ||
return None | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
didn't we use
unset
so users should define it explicitly and can avoid the sudden surprise when not setting env either by no knowledge/ignorance considered as unlimited?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We did but spec recommends using empty value as unlimited.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can try to convince others and update spec to accept "unset" as the value but for now I think we should update our SDK to make sure it is spec compatible.