-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Decouple the trace id struct generation from its encoding #3019
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3019 +/- ##
==========================================
- Coverage 77.00% 77.00% -0.01%
==========================================
Files 228 228
Lines 17066 17057 -9
==========================================
- Hits 13141 13134 -7
+ Misses 3082 3081 -1
+ Partials 843 842 -1
Flags with carried forward coverage won't be shown. Click here to find out more.
... and 3 files with indirect coverage changes Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. |
5af642d
to
472a0a7
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.
LGTM, just one comment
9353a00
to
6432fc5
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.
I think I was misunderstood.
As I go longer in comments - my main point was that the creation and the encoding are needlessly separated. There is nothing to do with a trace id apart from encoding it, so we can just get that as a single operation (newTraceID) that just returns the encoded traceid as a string. And forgo all the other types, methods and structs.
You were misunderstood indeed @mstoykov 😄 |
6432fc5
to
d8e31a4
Compare
d8e31a4
to
ead38b6
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.
LGTM!
This PR was triggered by this comment from @mstoykov. It intends to refactor the trace id structure, and its encoding method in a way that decouples them from each other.
Trace ids are serialised as 16 byte slices, which are in turn encoded into hexadecimal strings that are attached to requests HTTP headers. Some parts of the trace id have a fixed size, some others, a varying one (time, and random suffix). Because some of its parts have a varying size, we need to start serializing it to find out how much space is the random suffix gonna take.
Thus, in order to decouple the trace id creation from its encoding, we have made the trace id struct private (
traceId
) private, and exposed a trace id constructor (NewTraceID
) which returns an interface object implementing an interface that offers theEncode() (string, error)
method. That way, when the constructor is called, the serialization happens on the fly, and its result is stored in an internal field.🦖