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

Commit 71e98af

Browse files
authored
return empty list when encoding http header of undefined ctx (#124)
1 parent 3897ba1 commit 71e98af

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

src/oc_span_ctx_header.erl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@ encode(#span_ctx{trace_id=TraceId,
4343
Options = case TraceOptions band 1 of 1 -> <<"01">>; _ -> <<"00">> end,
4444
EncodedTraceId = io_lib:format("~32.16.0b", [TraceId]),
4545
EncodedSpanId = io_lib:format("~16.16.0b", [SpanId]),
46-
[?VERSION, "-", EncodedTraceId, "-", EncodedSpanId, "-", Options].
46+
[?VERSION, "-", EncodedTraceId, "-", EncodedSpanId, "-", Options];
47+
encode(undefined) ->
48+
[].
4749

4850
-spec decode(iodata()) -> maybe(opencensus:span_ctx()).
4951
decode(TraceContext) when is_list(TraceContext) ->

test/oc_span_ctx_SUITE.erl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ encode_decode_headers(_Config) ->
8989
InvalidBothIdsHeader = <<"00-00000000000000000000000000000000-0000000000000000-00">>,
9090
undefined = oc_span_ctx_header:decode(InvalidBothIdsHeader),
9191

92+
NoCtx = undefined,
93+
NoCtxEncoded = oc_span_ctx_header:encode(NoCtx),
94+
?assertEqual(NoCtx, oc_span_ctx_header:decode(NoCtxEncoded)),
9295

9396
%% Encode invalid trace contexts
9497
InvalidTC = #span_ctx{trace_id = 0,

0 commit comments

Comments
 (0)