Merge pull request 'Spawned processes inherit the parent's flow identity' (#3) from uw-inherit-flow into master

Reviewed-on: #3
This commit was merged in pull request #3.
This commit is contained in:
2026-06-06 03:56:57 +09:00
+18 -5
View File
@@ -7,6 +7,7 @@
]).
-export([ note_flow/1
, get_flow/0
, ct_log/2 %% ct_log(Fmt, Args)
, ct_log/3 %% ct_log(Flow, Fmt, Args)
, timestamp/0 ]).
@@ -44,9 +45,14 @@ get(Key, Default) ->
erase(Key) ->
gm_ctflow_state:erase(Key).
-spec note_flow(flow()) -> 'ok'.
note_flow(Flow) ->
erlang:put({?MODULE, flow}, Flow).
erlang:put({?MODULE, flow}, Flow),
ok.
-spec get_flow() -> flow() | 'undefined'.
get_flow() ->
erlang:get({?MODULE, flow}).
ct_log(Fmt, Args) ->
ct_log(erlang:get({?MODULE, flow}), Fmt, Args).
@@ -136,13 +142,20 @@ timestamp() ->
[Year,Month,Day,Hour,Min,Sec,MilliSec])).
spawn(F) ->
Flow = get_flow(),
proc_lib:spawn(fun() ->
maybe_inherit_flow(Flow),
ct_util:mark_process(),
F()
end).
spawn_opt(F, Opts) ->
Flow = get_flow(),
proc_lib:spawn_opt(fun() ->
ct_util:mark_process(),
F()
end, Opts).
maybe_inherit_flow(Flow),
ct_util:mark_process(),
F()
end, Opts).
maybe_inherit_flow(undefined) -> ok;
maybe_inherit_flow(Flow) -> note_flow(Flow).