-
Notifications
You must be signed in to change notification settings - Fork 105
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
make trace_id and span_id types binaries instead of integers #590
base: main
Are you sure you want to change the base?
Conversation
decide(TraceId, IdUpperBound) -> | ||
Lower64Bits = TraceId band ?MAX_VALUE, | ||
case erlang:abs(Lower64Bits) < IdUpperBound of | ||
decide(<<_:65, LowerBits:63>>, IdUpperBound) -> |
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 uh.. don't know why this is only 63 bits.. I just know that is what equaled the value I'd get with TraceId band ?MAX_VALUE
which I copied from somewhere else..
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.
So is there any kind of spec explaining this specific behavior? I guess this is just because ?MAX_VALUE
is the max 64 bits signed integer value (2^63-1) so that's unsurprising you'd look at the 63 lower bits, but I have no idea where the MAX_VALUE requirement comes from.
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.
Ah, the sign!
Trying to find now where it comes from.
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.
It may need to change (not in this PR) because the w3c spec now specifies 56 bits to be random if the new random trace id flag is set: https://w3c.github.io/trace-context/#random-trace-id-flag
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #590 +/- ##
==========================================
+ Coverage 38.16% 38.41% +0.24%
==========================================
Files 61 56 -5
Lines 3595 3512 -83
==========================================
- Hits 1372 1349 -23
+ Misses 2223 2163 -60
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
087f639
to
faac95a
Compare
faac95a
to
f541f41
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.
Sounds like the kind of stuff that's gonna be clearer for anyone working around the spec (even if it were to break some tests), and I figure in terms of interop leaving the confines of the VM it gets serialized as safely anyway.
It's likely to make some comparisons safer around zero signedness in values anyway.
decide(TraceId, IdUpperBound) -> | ||
Lower64Bits = TraceId band ?MAX_VALUE, | ||
case erlang:abs(Lower64Bits) < IdUpperBound of | ||
decide(<<_:65, LowerBits:63>>, IdUpperBound) -> |
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.
So is there any kind of spec explaining this specific behavior? I guess this is just because ?MAX_VALUE
is the max 64 bits signed integer value (2^63-1) so that's unsurprising you'd look at the 63 lower bits, but I have no idea where the MAX_VALUE requirement comes from.
Break the tests. This is technically a major breaking change but it is minimal. |
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.
🚀 💜
@DianaOlympos it broke tests you know about or do you just mean bc it broke tests in this repo? |
No i mean literally do it. Break the users :) |
IMHO any tests this would break will be straightforward to fix. I doubt there would be very many since I assume most folks are doing something like |
@marcdel that is what I figured as well. Maybe some check that it is |
So @bryannaegele has a good point, using a binary is more memory than an integer. The integer is 3 words for trace id and 2 words for a span id, while the binary in both cases is 6 words. A small amount until you have a massive amount of spans obviously. |
Thought I'd do a quick microbenchmark on my laptop:
I don't know if it makes up for the extra memory usage. |
I suppose we can at least switch to |
note: try to pull out the integer 2 bsl 127 - 1 into a constant and inject it instead of recomputing it for every iteration |
Barely budges when I change to use a constant:
|
I think this is cleaner. I'd be 100% on this change if it wasn't that technically users may be using the integers in tests and thus this will break their tests.