This repository has been archived by the owner on Oct 26, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from tsloughter/otep-66
separate context propagation otep
- Loading branch information
Showing
10 changed files
with
490 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
%%%------------------------------------------------------------------------ | ||
%% Copyright 2019, OpenTelemetry Authors | ||
%% Licensed under the Apache License, Version 2.0 (the "License"); | ||
%% you may not use this file except in compliance with the License. | ||
%% You may obtain a copy of the License at | ||
%% | ||
%% http://www.apache.org/licenses/LICENSE-2.0 | ||
%% | ||
%% Unless required by applicable law or agreed to in writing, software | ||
%% distributed under the License is distributed on an "AS IS" BASIS, | ||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
%% See the License for the specific language governing permissions and | ||
%% limitations under the License. | ||
%% | ||
%% @doc | ||
%% @end | ||
%%%------------------------------------------------------------------------- | ||
-module(ot_baggage). | ||
|
||
-export([ctx_key/0, | ||
set/2, | ||
get/1, | ||
remove/1, | ||
clear/0, | ||
get_http_propagators/0]). | ||
|
||
-type key() :: string(). | ||
-type value() :: string(). | ||
|
||
-export_type([key/0, | ||
value/0]). | ||
|
||
-define(BAGGAGE_KEY, '$__ot_baggage_ctx_key'). | ||
-define(BAGGAGE_HEADER, <<"Baggage-Context">>). | ||
ctx_key() -> | ||
?BAGGAGE_KEY. | ||
|
||
-spec set(key(), value()) -> ok. | ||
set(Key, Value) -> | ||
ot_ctx:set_value(?BAGGAGE_KEY, Key, Value). | ||
|
||
-spec get(key()) -> value(). | ||
get(Key)-> | ||
ot_ctx:get_value(?BAGGAGE_KEY, Key). | ||
|
||
-spec remove(key()) -> ok. | ||
remove(Key) -> | ||
ot_ctx:remove(?BAGGAGE_KEY, Key). | ||
|
||
-spec clear() -> ok. | ||
clear() -> | ||
ot_ctx:clear(?BAGGAGE_KEY). | ||
|
||
-spec get_http_propagators() -> {ot_propagation:http_extractor(), ot_propagation:http_injector()}. | ||
get_http_propagators() -> | ||
ToText = fun(_Headers, undefined) -> | ||
[]; | ||
(_Headers, Baggage) -> | ||
case maps:fold(fun(Key, Value, Acc) -> | ||
[$,, [Key, "=", Value] | Acc] | ||
end, [], Baggage) of | ||
[$, | List] -> | ||
[{?BAGGAGE_HEADER, List}]; | ||
_ -> | ||
[] | ||
end | ||
end, | ||
FromText = fun(Headers, CurrentBaggage) -> | ||
case lists:keyfind(?BAGGAGE_HEADER, 1, Headers) of | ||
{_, String} -> | ||
Pairs = string:lexemes(String, [","]), | ||
lists:foldl(fun(Pair, Acc) -> | ||
[Key, Value] = string:split(Pair, "="), | ||
Acc#{Key => {Value, unlimited_propagation}} | ||
end, CurrentBaggage, Pairs); | ||
_ -> | ||
CurrentBaggage | ||
end | ||
end, | ||
Inject = ot_ctx:http_injector(?BAGGAGE_KEY, ToText), | ||
Extract = ot_ctx:http_extractor(?BAGGAGE_KEY, FromText), | ||
{Extract, Inject}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
%%%------------------------------------------------------------------------ | ||
%% Copyright 2019, OpenTelemetry Authors | ||
%% Licensed under the Apache License, Version 2.0 (the "License"); | ||
%% you may not use this file except in compliance with the License. | ||
%% You may obtain a copy of the License at | ||
%% | ||
%% http://www.apache.org/licenses/LICENSE-2.0 | ||
%% | ||
%% Unless required by applicable law or agreed to in writing, software | ||
%% distributed under the License is distributed on an "AS IS" BASIS, | ||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
%% See the License for the specific language governing permissions and | ||
%% limitations under the License. | ||
%% | ||
%% @doc | ||
%% @end | ||
%%%------------------------------------------------------------------------- | ||
-module(ot_correlations). | ||
|
||
-export([ctx_key/0, | ||
set/3, | ||
get_http_propagators/0]). | ||
|
||
-type key() :: string(). | ||
-type value() :: string(). | ||
-type hop_limit() :: no_propagation | unlimited_propagation. | ||
|
||
-export_type([key/0, | ||
value/0]). | ||
|
||
-define(CORRELATIONS_KEY, '$__ot_correlations_ctx_key'). | ||
-define(CORRELATIONS_HEADER, <<"Correlation-Context">>). | ||
|
||
ctx_key() -> | ||
?CORRELATIONS_KEY. | ||
|
||
-spec set(key(), value(), hop_limit()) -> ok. | ||
set(Key, Value, HopLimit) -> | ||
ot_ctx:set_value(?CORRELATIONS_KEY, Key, {Value, HopLimit}). | ||
|
||
-spec get_http_propagators() -> {ot_propagation:http_extractor(), ot_propagation:http_injector()}. | ||
get_http_propagators() -> | ||
ToText = fun(_Headers, Correlations) -> | ||
case maps:fold(fun(Key, {Value, unlimited_propagation}, Acc) -> | ||
[$,, [Key, "=", Value] | Acc]; | ||
(_Key, {_Value, no_propagation}, Acc) -> | ||
Acc | ||
end, [], Correlations) of | ||
[$, | List] -> | ||
[{?CORRELATIONS_HEADER, List}]; | ||
_ -> | ||
[] | ||
end | ||
end, | ||
FromText = fun(Headers, CurrentCorrelations) -> | ||
case lists:keyfind(?CORRELATIONS_HEADER, 1, Headers) of | ||
{_, String} -> | ||
Pairs = string:lexemes(String, [","]), | ||
lists:foldl(fun(Pair, Acc) -> | ||
[Key, Value] = string:split(Pair, "="), | ||
Acc#{Key => {Value, unlimited_propagation}} | ||
end, CurrentCorrelations, Pairs); | ||
_ -> | ||
CurrentCorrelations | ||
end | ||
end, | ||
Inject = ot_ctx:http_injector(?CORRELATIONS_KEY, ToText), | ||
Extract = ot_ctx:http_extractor(?CORRELATIONS_KEY, FromText), | ||
{Extract, Inject}. |
Oops, something went wrong.