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

Commit

Permalink
LOG_INFO macro usage fix on earlier OTPs (#144)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
tsloughter committed Feb 27, 2019
1 parent b3ab781 commit 5e697cd
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 126 deletions.
164 changes: 44 additions & 120 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,127 +1,51 @@
defaults: &defaults
shell: /bin/sh
working_directory: /home/circleci/census
docker:
- image: erlang:21.2-alpine
cmd: ["/bin/sh"]
version: 2.1

version: 2
jobs:
build:
<<: *defaults
steps:
- checkout

- restore_cache:
keys:
- census-{{ checksum "rebar.lock" }}
- census-hex-packages

- run:
command: rebar3 compile

- store_artifacts:
path: /home/circleci/census/rebar3.crashdump
destination: rebar3_crashdump.txt
when: on_fail

- save-cache:
key: census-{{ checksum "rebar.lock" }}
paths:
- /home/circleci/census/_build/default/lib
- /home/circleci/census/_build/default/plugins

- save-cache:
key: census-hex-packages
paths:
- /root/.cache/rebar3/hex/default/packages
orbs:
rebar3: tsloughter/rebar3@0.6.3
codecov: codecov/codecov@1.0.4

dialyzer:
<<: *defaults
steps:
- checkout

- restore_cache:
keys:
- erlang-plt-21.2

- restore_cache:
keys:
- census-{{ checksum "rebar.lock" }}
- census-hex-packages

- run:
command: rebar3 dialyzer

- save-cache:
key: erlang-plt-21.2
paths:
- /root/.cache/rebar3/rebar3_21.2_plt
xref:
<<: *defaults
steps:
- checkout

- restore_cache:
keys:
- census-{{ checksum "rebar.lock" }}
- census-hex-packages

- run:
command: rebar3 xref

lint:
<<: *defaults
steps:
- checkout

- restore_cache:
keys:
- census-{{ checksum "rebar.lock" }}
- census-hex-packages

- run:
command: rebar3 lint

tests:
<<: *defaults
jobs:
build_and_test:
parameters:
tag:
description: The Erlang/OTP docker image tag to use
type: string
codecov_flag:
description: String the coverage reports are grouped by
type: string
executor:
name: rebar3/erlang
tag: <<parameters.tag>>
steps:
- checkout

- restore_cache:
keys:
- census-{{ checksum "rebar.lock" }}
- census-hex-packages

- run:
command: |
set -eux
rebar3 do ct, cover
rebar3 covertool generate
apk add --update python python-dev py-pip
pip install codecov && codecov -f _build/test/covertool/opencensus.covertool.xml
- store_test_results:
path: /home/circleci/census/_build/test/logs/

- store_artifacts:
path: /home/circleci/census/_build/test/logs
destination: common_test
- rebar3/with_deps_cache:
cache_key_postfix: -<<parameters.tag>>
steps:
- rebar3/compile
- rebar3/dialyzer
- run: rebar3 as test xref
- rebar3/ct

- store_test_results:
path: ~/project/_build/test/logs/
- store_artifacts:
path: ~/project/_build/test/logs
destination: common_test

- rebar3/cover
- run: rebar3 as test covertool generate
- codecov/upload:
file: _build/test/covertool/opencensus.covertool.xml
flags: <<parameters.codecov_flag>>

workflows:
version: 2
build_and_test:
run_all:
jobs:
- build
- dialyzer:
requires:
- build
- xref:
requires:
- build
- lint:
requires:
- build
- tests:
requires:
- build
- build_and_test:
name: "otp-21"
tag: "21.2"
codecov_flag: "otp21"
- build_and_test:
name: "otp-20"
tag: "20"
codecov_flag: "otp20"
7 changes: 4 additions & 3 deletions src/oc_propagation_http_b3.erl
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,9 @@ to_headers(#span_ctx{trace_id=TraceId,
span_id=SpanId,
trace_options=TraceOptions}) ->
Options = case TraceOptions band 1 of 1 -> "1"; _ -> "0" end,
EncodedTraceId = io_lib:format("~32.16.0b", [TraceId]),
EncodedSpanId = io_lib:format("~16.16.0b", [SpanId]),
%% iolist_to_binary only needed for versions before otp-21
EncodedTraceId = iolist_to_binary(io_lib:format("~32.16.0b", [TraceId])),
EncodedSpanId = iolist_to_binary(io_lib:format("~16.16.0b", [SpanId])),
[{?B3_TRACE_ID, EncodedTraceId},
{?B3_SPAN_ID, EncodedSpanId},
{?B3_SAMPLED, Options}];
Expand Down Expand Up @@ -84,7 +85,7 @@ trace_id(Headers) ->
span_id(Headers) ->
case lookup(?B3_SPAN_ID, Headers) of
SpanId when is_list(SpanId) orelse is_binary(SpanId) ->
case string:length(SpanId) =:= 32 orelse string:length(SpanId) =:= 16 of
case string:length(SpanId) =:= 16 of
true ->
SpanId;
_ ->
Expand Down
6 changes: 3 additions & 3 deletions src/oc_tracestate.erl
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,21 @@ new(undefined, Entries) ->
true ->
#tracestate{entries=Entries};
{false, Error} ->
?LOG_INFO(format_error(Error)),
?LOG_INFO(format_error(Error), []),
undefined
end;
new(#tracestate{entries=ParentEntries}, Entries) ->
case are_valid(Entries) of
true ->
case add(#tracestate{entries=ParentEntries}, Entries) of
{error, Reason} ->
?LOG_INFO(format_error(Reason)),
?LOG_INFO(format_error(Reason), []),
undefined;
Tracestate ->
Tracestate
end;
{false, Error} ->
?LOG_INFO(format_error(Error)),
?LOG_INFO(format_error(Error), []),
undefined
end.

Expand Down

0 comments on commit 5e697cd

Please sign in to comment.