Skip to content

fix: Use monotonic clock to compute durations - #631

Merged
untitaker merged 2 commits into
masterfrom
rhcarvalho/span-monotonic
Feb 27, 2020
Merged

untitaker merged 2 commits into
masterfrom
rhcarvalho/span-monotonic

Conversation

@rhcarvalho

@rhcarvalho rhcarvalho commented Feb 20, 2020 •

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
Contributor Author

@untitaker could you please have a look?

@untitaker untitaker left a comment

Copy link
Copy Markdown
Member

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
Copy Markdown
Member

💯

@rhcarvalho

Copy link
Copy Markdown
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
Copy Markdown
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