Allow looking up parent when parent is a named process (#261)

This commit is contained in:
Jeffery Utter 2024-02-12 16:27:19 -06:00 committed by GitHub
parent b15f575e0c
commit 52f84a64ea
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 24 additions and 1 deletions

View File

@ -39,7 +39,12 @@ fetch_ctx(Pid) ->
otel_ctx(Dictionary)
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) ->
case process_info(Pid, dictionary) of
{dictionary, Dict} ->

View File

@ -55,6 +55,24 @@ defmodule OpentelemetryProcessPropagatorTest do
assert_receive ^ctx
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
describe "fetch_parent_ctx/1" do