diff --git a/kong/globalpatches.lua b/kong/globalpatches.lua index a4f8e7c7b9c9..99c128560df1 100644 --- a/kong/globalpatches.lua +++ b/kong/globalpatches.lua @@ -596,29 +596,20 @@ return function(options) local hook_called = false _G.ngx.log = function(...) if hook_called then - -- detect recursive loops and yielding from the hook: + -- avoid recursive loops: relies on the hook handler to NOT yield old_ngx_log(ngx.ERR, debug.traceback("concurrent execution detected for: ngx.log", 2)) return old_ngx_log(...) end - -- The pcall surrounding `run_hook` is to ensure `hook_called` is always - -- reset to `false` after hook execution, even in case an error is thrown - -- by `run_hook`. - -- - -- stack level = 6: + -- stack level = 5: -- 1: maybe_push -- 2: dynamic_hook.pcall -- 3: dynamic_hook.run_hook -- 4: patched function - -- 5: pcall - -- 6: caller + -- 5: caller hook_called = true - local ok, err = pcall(dynamic_hook.run_hook, "observability_logs", "push", 6, ...) + dynamic_hook.run_hook("observability_logs", "push", 5, ...) hook_called = false - - if not ok then - old_ngx_log(ngx.ERR, debug.traceback("observability_logs hook failed: " .. err, 2)) - end return old_ngx_log(...) end -- export native ngx.log to be used where