Allow looking up parent when parent is a named process (#261)
This commit is contained in:
parent
b15f575e0c
commit
52f84a64ea
|
@ -39,7 +39,12 @@ fetch_ctx(Pid) ->
|
||||||
otel_ctx(Dictionary)
|
otel_ctx(Dictionary)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
-spec pdict(pid()) -> [{term(), term()}] | undefined.
|
-spec pdict(pid() | atom()) -> [{term(), term()}] | undefined.
|
||||||
|
pdict(Name) when is_atom(Name) ->
|
||||||
|
case whereis(Name) of
|
||||||
|
undefined -> undefined;
|
||||||
|
Pid -> pdict(Pid)
|
||||||
|
end;
|
||||||
pdict(Pid) ->
|
pdict(Pid) ->
|
||||||
case process_info(Pid, dictionary) of
|
case process_info(Pid, dictionary) of
|
||||||
{dictionary, Dict} ->
|
{dictionary, Dict} ->
|
||||||
|
|
|
@ -55,6 +55,24 @@ defmodule OpentelemetryProcessPropagatorTest do
|
||||||
|
|
||||||
assert_receive ^ctx
|
assert_receive ^ctx
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "fetches the parent ctx when parent is named" do
|
||||||
|
Process.register(self(), TestParent)
|
||||||
|
|
||||||
|
span_ctx = Tracer.start_span("test")
|
||||||
|
Tracer.set_current_span(span_ctx)
|
||||||
|
|
||||||
|
ctx = Ctx.get_current()
|
||||||
|
|
||||||
|
pid = self()
|
||||||
|
|
||||||
|
:proc_lib.spawn(fn ->
|
||||||
|
p_ctx = fetch_parent_ctx()
|
||||||
|
send(pid, p_ctx)
|
||||||
|
end)
|
||||||
|
|
||||||
|
assert_receive ^ctx
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "fetch_parent_ctx/1" do
|
describe "fetch_parent_ctx/1" do
|
||||||
|
|
Loading…
Reference in New Issue