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

Commit 838b22a

Browse files
committed
encode b3 headers without padding when not 32 chars
1 parent 7fb276f commit 838b22a

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/oc_propagation_http_b3.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ to_headers(#span_ctx{trace_id=TraceId,
3939
trace_options=TraceOptions}) ->
4040
Options = case TraceOptions band 1 of 1 -> "1"; _ -> "0" end,
4141
%% iolist_to_binary only needed for versions before otp-21
42-
EncodedTraceId = iolist_to_binary(io_lib:format("~32.16.0b", [TraceId])),
42+
EncodedTraceId = iolist_to_binary(io_lib:format("~.16b", [TraceId])),
4343
EncodedSpanId = iolist_to_binary(io_lib:format("~16.16.0b", [SpanId])),
4444
[{?B3_TRACE_ID, EncodedTraceId},
4545
{?B3_SPAN_ID, EncodedSpanId},

test/oc_span_ctx_SUITE.erl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,15 @@ b3_encode_decode_headers(_Config) ->
134134
compare_b3_headers(Encoded, Headers),
135135
?assertEqual(Decoded, oc_propagation_http_b3:from_headers(Encoded)),
136136

137+
%% TraceId: 4bf92f3577b34da6
138+
%% SpanId: 00f067aa0ba902b7
139+
%% Enabled: true
140+
ShortTraceIDHeaders = ?B3_HEADERS(<<"4bf92f3577b34da6">>, <<"00f067aa0ba902b7">>, <<"1">>),
141+
ShortTraceIDDecoded = oc_propagation_http_b3:from_headers(ShortTraceIDHeaders),
142+
ShortTraceIDEncoded = oc_propagation_http_b3:to_headers(ShortTraceIDDecoded),
143+
compare_b3_headers(ShortTraceIDEncoded, ShortTraceIDHeaders),
144+
?assertEqual(ShortTraceIDDecoded, oc_propagation_http_b3:from_headers(ShortTraceIDEncoded)),
145+
137146
%% TraceId: 4bf92f3577b34da6a3ce929d0e0e4736
138147
%% SpanId: 00f067aa0ba902b7
139148
%% Enabled: false

0 commit comments

Comments
 (0)