fix: pass stop_action_after_render=true in trace meta data

Even if there is no trace we still need to pass
stop_action_after_render=true in the trace meta data so that the action
will be stopped.
This commit is contained in:
Kjell Winblad 2024-04-12 11:38:01 +02:00
parent aa950f97fa
commit f444c6fc32
1 changed files with 20 additions and 8 deletions

View File

@ -471,23 +471,35 @@ do_handle_action(RuleId, #{mod := Mod, func := Func} = Action, Selected, Envs) -
Result. Result.
do_handle_action_get_trace_inc_metrics_context(RuleID, Action) -> do_handle_action_get_trace_inc_metrics_context(RuleID, Action) ->
case emqx_trace:list() of case {emqx_trace:list(), logger:get_process_metadata()} of
[] -> {[], #{stop_action_after_render := true}} ->
%% Even if there is no trace we still need to pass
%% stop_action_after_render in the trace meta data so that the
%% action will be stopped.
{
#{
stop_action_after_render => true
},
#{
rule_id => RuleID,
action_id => Action
}
};
{[], _} ->
%% As a performance/memory optimization, we don't create any trace %% As a performance/memory optimization, we don't create any trace
%% context if there are no trace patterns. %% context if there are no trace patterns.
{undefined, #{ {undefined, #{
rule_id => RuleID, rule_id => RuleID,
action_id => Action action_id => Action
}}; }};
_List -> {_List, TraceMeta} ->
Ctx = do_handle_action_get_trace_inc_metrics_context_unconditionally(Action), Ctx = do_handle_action_get_trace_inc_metrics_context_unconditionally(Action, TraceMeta),
{maps:remove(action_id, Ctx), Ctx} {maps:remove(action_id, Ctx), Ctx}
end. end.
do_handle_action_get_trace_inc_metrics_context_unconditionally(Action) -> do_handle_action_get_trace_inc_metrics_context_unconditionally(Action, TraceMeta) ->
Metadata = logger:get_process_metadata(), StopAfterRender = maps:get(stop_action_after_render, TraceMeta, false),
StopAfterRender = maps:get(stop_action_after_render, Metadata, false), case TraceMeta of
case Metadata of
#{ #{
rule_id := RuleID, rule_id := RuleID,
clientid := ClientID clientid := ClientID