Skip to content
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

span: use ns time directly rather than converting #964

Merged
merged 2 commits into from
Oct 17, 2019
Merged

Conversation

jd
Copy link
Contributor

@jd jd commented Jun 12, 2019

This improves span precision. Note that time_ns is only available on Python 3.

@jd jd requested a review from a team as a code owner June 12, 2019 13:05
brettlangdon
brettlangdon previously approved these changes Jun 12, 2019
Copy link
Member

@brettlangdon brettlangdon left a comment

Choose a reason for hiding this comment

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

nice, I dig it.

@brettlangdon brettlangdon added this to the 0.27.0 milestone Jun 12, 2019
@jd
Copy link
Contributor Author

jd commented Jun 12, 2019

Wait, actually, I thought it was smart to do this but… it somehow breaks the API. I mean users can pass their own start/stop time and so far we expected this to be in seconds. I don't think a lot of people do that, but if we now expect it to be nanoseconds, it'll break their spans. Damn.

Should we just give up on this?

@brettlangdon
Copy link
Member

oh, right... yeah, probably need to not do this for now.

@jd
Copy link
Contributor Author

jd commented Jun 12, 2019

Ok 😢 I'll rework it so it does not break the API.

@jd
Copy link
Contributor Author

jd commented Jun 20, 2019

This works and slightly breaks less the API: you still pass seconds as arguments, however the start attribute is now a nanoseconds timestamp, not a second one anymore.

WDYT?

Copy link
Member

@brettlangdon brettlangdon left a comment

Choose a reason for hiding this comment

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

this seems fine to me, wonder what can break from making this change for users.

@palazzem mind giving this a quick once over?

ddtrace/span.py Outdated
@@ -83,7 +82,7 @@ def __init__(
self.metrics = {}

# timing
self.start = start or time.time()
self.start = time_ns() if start is None else (start * 1e9)
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if we can handle this gracefully, like (start * 1e9) if not is_already_ns(start) else start.

This comment adds a little unnecessary complexity here, just pondering out loud.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, though there's no way to be sure it's already ns rather than guessing than a big number might need ns.

Another approach I'm just thinking about is that we could keep seconds but use float instead of int so if somebody passes a float it can pass nanoseconds and we can use nanoseconds by default too.

@majorgreys majorgreys modified the milestones: 0.27.0, 0.28.0 Jul 8, 2019
@brettlangdon brettlangdon modified the milestones: 0.28.0, 0.29.0 Aug 7, 2019
@brettlangdon
Copy link
Member

@jd is this a PR we want to continue working on?

@jd
Copy link
Contributor Author

jd commented Aug 20, 2019

@brettlangdon yes, it should be mergeable now. It improves things without breaking the API. We can break the API later if we think it's worth it.

@brettlangdon
Copy link
Member

The only thing I think that could cause an issue here is if someone is using span.start for something in their code.

@jd
Copy link
Contributor Author

jd commented Sep 19, 2019

You're right. Is it worth possibly breaking this? Considering we're in 0.x :)

@brettlangdon
Copy link
Member

Or we hold for 1.0.0 and break then.

@brettlangdon
Copy link
Member

We are 0.x but we still want to be stable.

This improves span precision. Note that time_ns is only available on Python 3.
@jd
Copy link
Contributor Author

jd commented Oct 17, 2019

This should be ready to be merged. It does not break the API anymore and make sure we use nanosecond precision when possible.

@jd jd requested a review from brettlangdon October 17, 2019 09:54
Copy link
Member

@brettlangdon brettlangdon left a comment

Choose a reason for hiding this comment

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

nice

@jd jd merged commit 84b77ee into DataDog:master Oct 17, 2019
@jd jd deleted the use-time-ns branch October 17, 2019 16:53
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.

None yet

3 participants