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

Commit

Permalink
encode b3 headers without padding when not 32 chars
Browse files Browse the repository at this point in the history
  • Loading branch information
castengo committed Jul 29, 2020
1 parent 7fb276f commit 838b22a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/oc_propagation_http_b3.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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])),
EncodedSpanId = iolist_to_binary(io_lib:format("~16.16.0b", [SpanId])),
[{?B3_TRACE_ID, EncodedTraceId},
{?B3_SPAN_ID, EncodedSpanId},
Expand Down
9 changes: 9 additions & 0 deletions test/oc_span_ctx_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,15 @@ b3_encode_decode_headers(_Config) ->
compare_b3_headers(Encoded, Headers),
?assertEqual(Decoded, oc_propagation_http_b3:from_headers(Encoded)),

%% TraceId: 4bf92f3577b34da6
%% SpanId: 00f067aa0ba902b7
%% Enabled: true
ShortTraceIDHeaders = ?B3_HEADERS(<<"4bf92f3577b34da6">>, <<"00f067aa0ba902b7">>, <<"1">>),
ShortTraceIDDecoded = oc_propagation_http_b3:from_headers(ShortTraceIDHeaders),
ShortTraceIDEncoded = oc_propagation_http_b3:to_headers(ShortTraceIDDecoded),
compare_b3_headers(ShortTraceIDEncoded, ShortTraceIDHeaders),
?assertEqual(ShortTraceIDDecoded, oc_propagation_http_b3:from_headers(ShortTraceIDEncoded)),

%% TraceId: 4bf92f3577b34da6a3ce929d0e0e4736
%% SpanId: 00f067aa0ba902b7
%% Enabled: false
Expand Down

0 comments on commit 838b22a

Please sign in to comment.