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

Commit 5e697cd

Browse files
authored
LOG_INFO macro usage fix on earlier OTPs (#144)
* on pre otp-21 LOG_INFO macro requires 2 arguments * run circleci testsagainst otp 18 19 20 and 21 * run tests on 20 and 21 * fix path to covertool file * add iolist_to_binary for otp 20 support of integer to string * b3 span id can onlybe 16 chars
1 parent b3ab781 commit 5e697cd

File tree

3 files changed

+51
-126
lines changed

3 files changed

+51
-126
lines changed

.circleci/config.yml

Lines changed: 44 additions & 120 deletions
Original file line numberDiff line numberDiff line change
@@ -1,127 +1,51 @@
1-
defaults: &defaults
2-
shell: /bin/sh
3-
working_directory: /home/circleci/census
4-
docker:
5-
- image: erlang:21.2-alpine
6-
cmd: ["/bin/sh"]
1+
version: 2.1
72

8-
version: 2
9-
jobs:
10-
build:
11-
<<: *defaults
12-
steps:
13-
- checkout
14-
15-
- restore_cache:
16-
keys:
17-
- census-{{ checksum "rebar.lock" }}
18-
- census-hex-packages
19-
20-
- run:
21-
command: rebar3 compile
22-
23-
- store_artifacts:
24-
path: /home/circleci/census/rebar3.crashdump
25-
destination: rebar3_crashdump.txt
26-
when: on_fail
27-
28-
- save-cache:
29-
key: census-{{ checksum "rebar.lock" }}
30-
paths:
31-
- /home/circleci/census/_build/default/lib
32-
- /home/circleci/census/_build/default/plugins
33-
34-
- save-cache:
35-
key: census-hex-packages
36-
paths:
37-
- /root/.cache/rebar3/hex/default/packages
3+
orbs:
4+
rebar3: tsloughter/rebar3@0.6.3
5+
codecov: codecov/codecov@1.0.4
386

39-
dialyzer:
40-
<<: *defaults
41-
steps:
42-
- checkout
43-
44-
- restore_cache:
45-
keys:
46-
- erlang-plt-21.2
47-
48-
- restore_cache:
49-
keys:
50-
- census-{{ checksum "rebar.lock" }}
51-
- census-hex-packages
52-
53-
- run:
54-
command: rebar3 dialyzer
55-
56-
- save-cache:
57-
key: erlang-plt-21.2
58-
paths:
59-
- /root/.cache/rebar3/rebar3_21.2_plt
60-
xref:
61-
<<: *defaults
62-
steps:
63-
- checkout
64-
65-
- restore_cache:
66-
keys:
67-
- census-{{ checksum "rebar.lock" }}
68-
- census-hex-packages
69-
70-
- run:
71-
command: rebar3 xref
72-
73-
lint:
74-
<<: *defaults
75-
steps:
76-
- checkout
77-
78-
- restore_cache:
79-
keys:
80-
- census-{{ checksum "rebar.lock" }}
81-
- census-hex-packages
82-
83-
- run:
84-
command: rebar3 lint
85-
86-
tests:
87-
<<: *defaults
7+
jobs:
8+
build_and_test:
9+
parameters:
10+
tag:
11+
description: The Erlang/OTP docker image tag to use
12+
type: string
13+
codecov_flag:
14+
description: String the coverage reports are grouped by
15+
type: string
16+
executor:
17+
name: rebar3/erlang
18+
tag: <<parameters.tag>>
8819
steps:
8920
- checkout
90-
91-
- restore_cache:
92-
keys:
93-
- census-{{ checksum "rebar.lock" }}
94-
- census-hex-packages
95-
96-
- run:
97-
command: |
98-
set -eux
99-
rebar3 do ct, cover
100-
rebar3 covertool generate
101-
apk add --update python python-dev py-pip
102-
pip install codecov && codecov -f _build/test/covertool/opencensus.covertool.xml
103-
104-
- store_test_results:
105-
path: /home/circleci/census/_build/test/logs/
106-
107-
- store_artifacts:
108-
path: /home/circleci/census/_build/test/logs
109-
destination: common_test
21+
- rebar3/with_deps_cache:
22+
cache_key_postfix: -<<parameters.tag>>
23+
steps:
24+
- rebar3/compile
25+
- rebar3/dialyzer
26+
- run: rebar3 as test xref
27+
- rebar3/ct
28+
29+
- store_test_results:
30+
path: ~/project/_build/test/logs/
31+
- store_artifacts:
32+
path: ~/project/_build/test/logs
33+
destination: common_test
34+
35+
- rebar3/cover
36+
- run: rebar3 as test covertool generate
37+
- codecov/upload:
38+
file: _build/test/covertool/opencensus.covertool.xml
39+
flags: <<parameters.codecov_flag>>
11040

11141
workflows:
112-
version: 2
113-
build_and_test:
42+
run_all:
11443
jobs:
115-
- build
116-
- dialyzer:
117-
requires:
118-
- build
119-
- xref:
120-
requires:
121-
- build
122-
- lint:
123-
requires:
124-
- build
125-
- tests:
126-
requires:
127-
- build
44+
- build_and_test:
45+
name: "otp-21"
46+
tag: "21.2"
47+
codecov_flag: "otp21"
48+
- build_and_test:
49+
name: "otp-20"
50+
tag: "20"
51+
codecov_flag: "otp20"

src/oc_propagation_http_b3.erl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ to_headers(#span_ctx{trace_id=TraceId,
3838
span_id=SpanId,
3939
trace_options=TraceOptions}) ->
4040
Options = case TraceOptions band 1 of 1 -> "1"; _ -> "0" end,
41-
EncodedTraceId = io_lib:format("~32.16.0b", [TraceId]),
42-
EncodedSpanId = io_lib:format("~16.16.0b", [SpanId]),
41+
%% iolist_to_binary only needed for versions before otp-21
42+
EncodedTraceId = iolist_to_binary(io_lib:format("~32.16.0b", [TraceId])),
43+
EncodedSpanId = iolist_to_binary(io_lib:format("~16.16.0b", [SpanId])),
4344
[{?B3_TRACE_ID, EncodedTraceId},
4445
{?B3_SPAN_ID, EncodedSpanId},
4546
{?B3_SAMPLED, Options}];
@@ -84,7 +85,7 @@ trace_id(Headers) ->
8485
span_id(Headers) ->
8586
case lookup(?B3_SPAN_ID, Headers) of
8687
SpanId when is_list(SpanId) orelse is_binary(SpanId) ->
87-
case string:length(SpanId) =:= 32 orelse string:length(SpanId) =:= 16 of
88+
case string:length(SpanId) =:= 16 of
8889
true ->
8990
SpanId;
9091
_ ->

src/oc_tracestate.erl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,21 @@ new(undefined, Entries) ->
5050
true ->
5151
#tracestate{entries=Entries};
5252
{false, Error} ->
53-
?LOG_INFO(format_error(Error)),
53+
?LOG_INFO(format_error(Error), []),
5454
undefined
5555
end;
5656
new(#tracestate{entries=ParentEntries}, Entries) ->
5757
case are_valid(Entries) of
5858
true ->
5959
case add(#tracestate{entries=ParentEntries}, Entries) of
6060
{error, Reason} ->
61-
?LOG_INFO(format_error(Reason)),
61+
?LOG_INFO(format_error(Reason), []),
6262
undefined;
6363
Tracestate ->
6464
Tracestate
6565
end;
6666
{false, Error} ->
67-
?LOG_INFO(format_error(Error)),
67+
?LOG_INFO(format_error(Error), []),
6868
undefined
6969
end.
7070

0 commit comments

Comments
 (0)