Skip to content

fix: Use monotonic clock to compute durations #631

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

Merged
merged 2 commits into from
Feb 27, 2020

Conversation

rhcarvalho
Copy link
Contributor

@rhcarvalho rhcarvalho commented Feb 20, 2020

In summary, care must be taken when computing durations. Monotonic
clocks are not subject to system clock adjustments or system clock skew.
The difference between any two chronologically recorded time values is
guaranteed to never be negative.

The same guarantee above does not exist for the difference between two
calls to datetime.now() and friends.

More details and rationale see PEP 418.

Resources:

PEP 418 -- Add monotonic time, performance counter, and process time functions
https://www.python.org/dev/peps/pep-0418/

PEP 564 -- Add new time functions with nanosecond resolution
https://www.python.org/dev/peps/pep-0564/


Know limitation

At present, we only address timestamp computation within a single span.
A more complete patch should compute all durations in a transaction using a monotonic clock and set all timestamps relative to a single reading of a wall clock time source.

@rhcarvalho rhcarvalho requested a review from untitaker February 20, 2020 00:58
@rhcarvalho
Copy link
Contributor Author

Related: getsentry/sentry-javascript#2441

In summary, care must be taken when computing durations. Monotonic
clocks are not subject to system clock adjustments or system clock skew.
The difference between any two chronologically recorded time values is
guaranteed to never be negative.

The same guarantee above does not exist for the difference between two
calls to datetime.now() and friends.

More details and rationale see PEP 418.

Resources:

PEP 418 -- Add monotonic time, performance counter, and process time functions
https://www.python.org/dev/peps/pep-0418/

PEP 564 -- Add new time functions with nanosecond resolution
https://www.python.org/dev/peps/pep-0564/
@rhcarvalho rhcarvalho force-pushed the rhcarvalho/span-monotonic branch from 42f2f41 to 5c3f81c Compare February 26, 2020 16:51
@rhcarvalho
Copy link
Contributor Author

@untitaker could you please have a look?

Copy link
Member

@untitaker untitaker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the slow response. I did indeed look at your PR yesterday and went on an unsuccessful detour on how to configure a linter that would prevent you from writing durationSeconds. I've just pushed the rename for now.

@untitaker untitaker merged commit d31e805 into master Feb 27, 2020
@untitaker untitaker deleted the rhcarvalho/span-monotonic branch February 27, 2020 10:41
@untitaker
Copy link
Member

💯

@rhcarvalho
Copy link
Contributor Author

how to configure a linter that would prevent you from writing durationSeconds.

Shame on me 🤦‍♂️

Thanks for noticing! I can only blame on doing the JavaScript and Python changes simultaneously 😄

@untitaker
Copy link
Member

I think the bigger shame is that there is no lint against this and that I couldn't figure out how to configure one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants