Skip to content

Commit

Permalink
implement seq_trace based context
Browse files Browse the repository at this point in the history
  • Loading branch information
tsloughter committed Aug 24, 2019
1 parent 1dfe015 commit acd6811
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 10 deletions.
37 changes: 29 additions & 8 deletions src/ot_ctx_seqtrace.erl
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,38 @@
with_value/3]).

-spec get(term()) -> term().
get(_Key) ->
ok.
get(Key) ->
case seq_trace:get_token(label) of
{label, Label} ->
maps:get(Key, Label, undefined);
[] ->
undefined
end.

-spec get(term(), term()) -> term().
get(_Key, _Value) ->
ok.
get(Key, Default) ->
case seq_trace:get_token(label) of
{label, Label} ->
maps:get(Key, Label, Default);
[] ->
undefined
end.

-spec with_value(term(), term()) -> ok.
with_value(_Key, _Value) ->
ok.
with_value(Key, Value) ->
case seq_trace:get_token(label) of
{label, Label} ->
seq_trace:set_token(label, Label#{Key => Value});
[] ->
seq_trace:set_token(label, #{Key => Value})
end.

-spec with_value(term(), term(), fun()) -> ok.
with_value(_Key, _Value, Fun) ->
Fun().
with_value(Key, Value, Fun) ->
Orig = ?MODULE:get(Key),
try
with_value(Key, Value),
Fun()
after
with_value(Key, Orig)
end.
19 changes: 17 additions & 2 deletions test/opentelemetry_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,30 @@
-include("opentelemetry.hrl").

all() ->
[{group, ot_ctx_pdict},
{group, ot_ctx_seqtrace}].

all_testcases() ->
[child_spans, non_default_tracer].

groups() ->
[{ot_ctx_pdict, [parallel, shuffle], all_testcases()},
{ot_ctx_seqtrace, [parallel, shuffle], all_testcases()}].

init_per_suite(Config) ->
application:load(opentelemetry),
%% set application environment variables
{ok, _} = application:ensure_all_started(opentelemetry),
Config.

end_per_suite(_Config) ->
ok.

init_per_group(CtxModule, Config) ->
application:set_env(opentelemetry, tracer, {ot_tracer_default, #{span => {ot_span_ets, []},
ctx => {CtxModule, []}}}),
{ok, _} = application:ensure_all_started(opentelemetry),
Config.

end_per_group(_, _Config) ->
ok = application:stop(opentelemetry).

init_per_testcase(_, Config) ->
Expand Down

0 comments on commit acd6811

Please sign in to comment.