Skip to content

Commit acd6811

Browse files
committed
implement seq_trace based context
1 parent 1dfe015 commit acd6811

File tree

2 files changed

+46
-10
lines changed

2 files changed

+46
-10
lines changed

src/ot_ctx_seqtrace.erl

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,38 @@
2525
with_value/3]).
2626

2727
-spec get(term()) -> term().
28-
get(_Key) ->
29-
ok.
28+
get(Key) ->
29+
case seq_trace:get_token(label) of
30+
{label, Label} ->
31+
maps:get(Key, Label, undefined);
32+
[] ->
33+
undefined
34+
end.
3035

3136
-spec get(term(), term()) -> term().
32-
get(_Key, _Value) ->
33-
ok.
37+
get(Key, Default) ->
38+
case seq_trace:get_token(label) of
39+
{label, Label} ->
40+
maps:get(Key, Label, Default);
41+
[] ->
42+
undefined
43+
end.
3444

3545
-spec with_value(term(), term()) -> ok.
36-
with_value(_Key, _Value) ->
37-
ok.
46+
with_value(Key, Value) ->
47+
case seq_trace:get_token(label) of
48+
{label, Label} ->
49+
seq_trace:set_token(label, Label#{Key => Value});
50+
[] ->
51+
seq_trace:set_token(label, #{Key => Value})
52+
end.
3853

3954
-spec with_value(term(), term(), fun()) -> ok.
40-
with_value(_Key, _Value, Fun) ->
41-
Fun().
55+
with_value(Key, Value, Fun) ->
56+
Orig = ?MODULE:get(Key),
57+
try
58+
with_value(Key, Value),
59+
Fun()
60+
after
61+
with_value(Key, Orig)
62+
end.

test/opentelemetry_SUITE.erl

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,30 @@
88
-include("opentelemetry.hrl").
99

1010
all() ->
11+
[{group, ot_ctx_pdict},
12+
{group, ot_ctx_seqtrace}].
13+
14+
all_testcases() ->
1115
[child_spans, non_default_tracer].
1216

17+
groups() ->
18+
[{ot_ctx_pdict, [parallel, shuffle], all_testcases()},
19+
{ot_ctx_seqtrace, [parallel, shuffle], all_testcases()}].
20+
1321
init_per_suite(Config) ->
1422
application:load(opentelemetry),
15-
%% set application environment variables
16-
{ok, _} = application:ensure_all_started(opentelemetry),
1723
Config.
1824

1925
end_per_suite(_Config) ->
26+
ok.
27+
28+
init_per_group(CtxModule, Config) ->
29+
application:set_env(opentelemetry, tracer, {ot_tracer_default, #{span => {ot_span_ets, []},
30+
ctx => {CtxModule, []}}}),
31+
{ok, _} = application:ensure_all_started(opentelemetry),
32+
Config.
33+
34+
end_per_group(_, _Config) ->
2035
ok = application:stop(opentelemetry).
2136

2237
init_per_testcase(_, Config) ->

0 commit comments

Comments
 (0)