Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

format b3 headers as 16 chars when 64 bit #166

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

castengo
Copy link

@castengo castengo commented Jul 29, 2020

Since b3 trace IDs can be either 64 or 128 bit, we should check the size of the traceID and encode it according to its size instead of always encoding it as 32 chars.

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@castengo
Copy link
Author

@googlebot I signed it!

@googlebot
Copy link

CLAs look good, thanks!

ℹ️ Googlers: Go here for more info.

@@ -39,7 +39,7 @@ to_headers(#span_ctx{trace_id=TraceId,
trace_options=TraceOptions}) ->
Options = case TraceOptions band 1 of 1 -> "1"; _ -> "0" end,
%% iolist_to_binary only needed for versions before otp-21
EncodedTraceId = iolist_to_binary(io_lib:format("~32.16.0b", [TraceId])),
EncodedTraceId = iolist_to_binary(io_lib:format("~.16b", [TraceId])),
Copy link
Author

Choose a reason for hiding this comment

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

I can either do this or check if the integer is between -9,223,372,036,854,775,808 and 9,223,372,036,854,775,807 in a guard. Thought this might be better?

Copy link
Author

Choose a reason for hiding this comment

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

I can also do binary:encode_unsigned(TraceId) and check if its size 64 or 128 before formatting it. Let me know which approach you prefer.

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

Successfully merging this pull request may close these issues.

2 participants