Skip to content

Commit

Permalink
Merge branch 'main' into exporter-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
tsloughter authored Oct 18, 2021
2 parents 00c9eaa + 52f24d8 commit 21906cf
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 15 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/w3c_interop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: W3C Interop

on:
pull_request:
branches:
- 'main'
push:
branches:
- 'main'

jobs:
interop_tests:
name: Run W3C Trace Context Interop Tests
runs-on: ubuntu-18.04
env:
OTP_VERSION:
steps:
- uses: actions/checkout@v2
- uses: erlef/setup-beam@v1
with:
otp-version: '24.1.2'
- uses: actions/cache@v2
name: Cache
with:
path: |
_build
key: ${{ runner.os }}-build-${{ matrix.otp_version }}-${{ hashFiles(format('rebar.lock')) }}-1
restore-keys: |
${{ runner.os }}-build-${{ matrix.otp_version }}-1-
- name: Compile
run: rebar3 as interop compile

- uses: actions/checkout@v2
repository: 'https://github.com/w3c/trace-context'
path: 'trace-context'
- name: Setup python
uses: actions/setup-python@v2
with:
python-version: 3.6
architecture: x64
- run: pip install aiohttp
- run: |
erl -noinput -pa ./_build/interop/extras/interop/ $(rebar3 as interop path) -s w3c_trace_context_interop &
cd trace-context/test
python3 test.py http://127.0.0.1:5000/test
shell: bash
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [API 1.0.0-rc.3.2] - 2021-10-13

##### Fixed

- `otel_propagator_trace_context:extract/1` no longer crashes on `undefined`
header values

## [API 1.0.0-rc.3.1] - 2021-10-12

##### Fixed

- Properly published the package with Erlang and Elixir source. Package for
1.0.0-rc.3 was retired on Hex.pm

## [API 1.0.0-rc.3] - 2021-10-12

### Removed
Expand Down
2 changes: 1 addition & 1 deletion apps/opentelemetry_api/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.0-rc.3
1.0.0-rc.3.2
10 changes: 6 additions & 4 deletions apps/opentelemetry_api/src/otel_propagator_trace_context.erl
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,11 @@ encode_traceparent(TraceId, SpanId, TraceOptions) ->
EncodedSpanId = io_lib:format("~16.16.0b", [SpanId]),
iolist_to_binary([?VERSION, "-", EncodedTraceId, "-", EncodedSpanId, "-", Options]).

encode_tracestate(Entries) ->
encode_tracestate(Entries=[_|_]) ->
StateHeaderValue = lists:join($,, [[Key, $=, Value] || {Key, Value} <- Entries]),
unicode:characters_to_binary(StateHeaderValue).
unicode:characters_to_binary(StateHeaderValue);
encode_tracestate(_) ->
<<>>.

split(Pair) ->
case string:split(Pair, "=", all) of
Expand Down Expand Up @@ -172,10 +174,10 @@ parse_pairs([Pair | Rest], Acc) ->
andalso re:run(V, ?VALUE_MP) =/= nomatch
of
false ->
undefined;
[];
true ->
parse_pairs(Rest, Acc ++ [{K, V}])
end;
undefined ->
undefined
[]
end.
27 changes: 17 additions & 10 deletions interop/w3c_trace_context_interop.erl
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@
%%%-----------------------------------------------------------------------
-module(w3c_trace_context_interop).

-export([run/0,
-export([start/0,
do/1]).

-include_lib("inets/include/httpd.hrl").
-include_lib("opentelemetry_api/include/opentelemetry.hrl").
-include_lib("opentelemetry_api/include/otel_tracer.hrl").

run() ->
start() ->
application:ensure_all_started(inets),
application:ensure_all_started(opentelemetry),

{ok, _Pid} = inets:start(httpd, [{port, 5000},
{server_root, "/tmp"},
{document_root, "/tmp"},
Expand All @@ -42,14 +45,18 @@ do(Req) ->

lists:foreach(fun(#{<<"arguments">> := Arguments,
<<"url">> := Url}) ->
otel_propagator:http_extract(Headers),
?start_span(<<"interop-test">>),
InjectedHeaders = otel_propagator:http_inject([]),
httpc:request(post, {binary_to_list(Url),
headers_to_list(InjectedHeaders),
"application/json",
jsone:encode(Arguments)}, [], [{body_format, binary}]),
?end_span(opentelemetry:timestmap())
%% not really needed, but just to be safe
otel_ctx:clear(),

otel_propagator_text_map:extract(Headers),
?with_span(<<"interop-test">>, #{},
fun(_) ->
InjectedHeaders = otel_propagator_text_map:inject([]),
httpc:request(post, {binary_to_list(Url),
headers_to_list(InjectedHeaders),
"application/json",
jsone:encode(Arguments)}, [], [{body_format, binary}])
end)
end, List),

{proceed, [{response, {200, "ok"}}]}.
Expand Down

0 comments on commit 21906cf

Please sign in to comment.