-
Notifications
You must be signed in to change notification settings - Fork 696
Remove time_ns from API #1602
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
Remove time_ns from API #1602
Conversation
1de57e3
to
f3a3278
Compare
Right now we do this:
Now, this PR as it is right now "satisfies" the 3 points mentioned above:
I believe this PR to be a bit controversial since it uses a kind of a "hack" to fix this problem, it uses a Of the 3 points mentioned before, I care mostly about 2 and 3. In the past SIG it was suggested another possible solution, to not provide a @lzchen, @codeboten, @aabmass and anyone who may have an opinion, please leave it in the comments below. If more prefer the more traditional approach of just making |
This makes a lot of sense to me. We can just mark it as internal so we don't cover it under any API stability guarantees. I think this should be good enough for us to use the function internally. Anyone else deciding to use it would take on an intentional risk. Going out of the way with the sitecustomize trick isn't worth it IMHO. |
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.
+1 for making time_ns
as private instead of patching the time
module.
+1 |
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.
+1 to the other reviewers concerns about patching in this fashion. Definitely seems easy to make this a private function.
2f13261
to
8e0c8ed
Compare
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.
Just looking through the change, there's a lot of changes that don't appear to be directly tied to removing time_ns
from the API, is it possible to refactor this PR to only that code?
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.
Thanks the changes look good, but I think the warning could be more succinct.
from logging import getLogger | ||
from sys import version_info | ||
|
||
if version_info.minor < 7: |
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.
IMO a safer way to do this is:
try:
from time import time_ns
except ImportError:
def _time_ns....
This avoids anything funky with backported functions and the like.
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.
Sorry, how can this avoid anything funky with backported functions? I prefer the if
approach because it is not-exceptional for our users to use 3.6 or 3.5 so it should not be treated as an exception.
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.
Sorry, how can this avoid anything funky with backported functions?
In the past, people have backported python features back to older versions of python. It's common for them to use the same module name, or modify an existing module to include the functionality they backported.
There's no guarantee that the version of python doesn't have some version of the function backported. Hence I was saying that it's more common to just check to see if the import fails, and if it doesn't, then import the function.
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.
Ok, but we are not adding anything to any existing module now, I mean, we no longer try to patch time
. _time_ns
is always an attribute of opentelemetry.util
regardless of the Python version used, only its implementation changes.
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.
I'm more concerned about anyone patching the module. In the examples above, someone else could add time_ns, and if it exists, it would be nice to do so.
But this isn't a blocker comment, practically I don't think this will make much of a difference.
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.
@toumorokoshi
Is this resolved?
|
||
if version_info.minor < 7: | ||
getLogger(__name__).warning( # pylint: disable=logging-not-lazy | ||
"You are using Python version 3.%s. This version does not include a " |
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.
I think this is more verbose that it needs to be. It's a good code comment for maintainers, but for users it suffices to say "in this version of python, opentelemetry only supports millisecond-level granularity".
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.
In addition, why give the context that this private function will be removed once opentelemetry-api doesn't support python 3.7? I feel like that's somewhat obvious, and also unnecessary information to the user since 3.7+ supports NS granularity.
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.
Yes, you are right. I preferred to err on the safe side and be too verbose to make sure that our users never try using _time_ns
. Refactoring this.
|
||
if version_info.minor < 7: | ||
getLogger(__name__).warning( # pylint: disable=logging-not-lazy | ||
"You are using Python version 3.%s. This version does not include a " |
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.
In addition, why give the context that this private function will be removed once opentelemetry-api doesn't support python 3.7? I feel like that's somewhat obvious, and also unnecessary information to the user since 3.7+ supports NS granularity.
Fixes open-telemetry#1598 This refactors utils to make them private the most as possible
This PR depends on #1599, I have marked this PR as a draft until #1599 gets merged to avoid trouble when reviewing.
Description
This removes
time_ns
from our API. We were providing this only to support Python versions older than 3.7 that did not includetime_ns
as a function oftime
. The problem with the current approach is that it provides a function that does not have the resolution that the newtime_ns
provides, it is misleading for our users to have a function namedtime_ns
that does not provide actual nanosecond resolution. Having this function in our API is problematic, having a function that returns the time in nanoseconds is not part of the spec and makes us have to support it in future versions.The solution here artificially adds a function named
time_ns
totime
for Python versions older than 3.7. With this approach, our users can always dofrom time import time_ns
and when we decide not to support Python 3.5 (which has reached end of life already) or Python 3.6 (which will reach end of life by the end of this year) then we can simply remove this solution. This will be completely transparent to our users because they will never import anytime_ns
function from anopentelemetry
package.Fixes #1594
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Does This PR Require a Contrib Repo Change?
Answer the following question based on these examples of changes that would require a Contrib Repo Change:
The OTel specification has changed which prompted this PR to update the method interfaces of
opentelemetry-api/
oropentelemetry-sdk/
The method interfaces of
opentelemetry-instrumentation/
have changedThe method interfaces of
test/util
have changedScripts in
scripts/
that were copied over to the Contrib repo have changedConfiguration files that were copied over to the Contrib repo have changed (when consistency between repositories is applicable) such as in
pyproject.toml
isort.cfg
.flake8
When a new
.github/CODEOWNER
is addedMajor changes to project information, such as in:
README.md
CONTRIBUTING.md
Yes. - Link to PR: Sync with Remove time_ns from API opentelemetry-python-contrib#342
No.
Checklist: