Fix limit env vars unset/unlimited values#2054
Conversation
|
Builds on top of #2044. Should be rebased and reviewed after 2044 is merged. |
| - Its length is greater than the maximum allowed length. | ||
| - It needs to be encoded/decoded e.g, bytes to strings. |
There was a problem hiding this comment.
Nit: Looks like no cleaning is needed if value is not string or bytes, if this is checked first then all the remaining execution in this function can be saved.
There was a problem hiding this comment.
We also need to clean the string/byte value in sequences (and validate them) so can't bail out
| if key is None or key == "": | ||
| _logger.warning("invalid key `%s` (empty or null)", key) | ||
| return None | ||
|
|
There was a problem hiding this comment.
| if isinstance(value, (int, float, bool)): | |
| return True |
| if isinstance(value, bytes): | ||
| try: | ||
| value = value.decode() | ||
| except ValueError: |
There was a problem hiding this comment.
| except ValueError: | |
| except UnicodeDecodeError: |
| _DEFAULT_OTEL_LINK_ATTRIBUTE_COUNT_LIMIT = 128 | ||
|
|
||
|
|
||
| _ENV_VALUE_UNSET = "unset" |
There was a problem hiding this comment.
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.
We did but spec recommends using empty value as unlimited.
There was a problem hiding this comment.
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.
| 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.
Maybe I'm not fully understanding this scenario. When will value ever be "unset"? Isn't value supposed to be an int?
There was a problem hiding this comment.
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.
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.
Co-authored-by: Leighton Chen <lechen@microsoft.com>
Description
Limit env vars set to an empty value will be treated as unset/unlimited.
Fixes #2052
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Does This PR Require a Contrib Repo Change?
Checklist: