From 2da2b71d835b3a50da03dcea79a731b8bf95d66e Mon Sep 17 00:00:00 2001 From: xuruidong Date: Sat, 22 Nov 2025 19:32:13 +0800 Subject: [PATCH] feat(debug): add print_traceback for debugging --- apisix/debug.lua | 10 ++++++++++ t/debug/hook.t | 30 ++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) diff --git a/apisix/debug.lua b/apisix/debug.lua index 588f02aca438..5ecbb40ff650 100644 --- a/apisix/debug.lua +++ b/apisix/debug.lua @@ -77,6 +77,9 @@ local config_schema = { is_print_return_value = { type = "boolean", }, + is_print_traceback = { + type = "boolean", + }, } }, }, @@ -192,6 +195,13 @@ local function apply_new_fun(module, fun_name, file_path, hook_conf) end end + if hook_conf.is_print_traceback then + if enable_by_hook or enable_by_header_filter then + log[log_level]("call require(\"", file_path, "\").", fun_name, + "() call stack:", debug.traceback()) + end + end + local ret = {self.fun_org(...)} if hook_conf.is_print_return_value then if enable_by_hook or enable_by_header_filter then diff --git a/t/debug/hook.t b/t/debug/hook.t index 891e56c04b3b..e54de1c1a26b 100644 --- a/t/debug/hook.t +++ b/t/debug/hook.t @@ -151,3 +151,33 @@ hello world --- error_log read_debug_yaml(): failed to validate debug config property "hook_conf" is required --- wait: 3 + + + +=== TEST 6: basic print_traceback enabled with static hook +--- debug_config +basic: + enable: true +http_filter: + enable: false +hook_conf: + enable: true + name: hook_test + log_level: warn + is_print_input_args: false + is_print_return_value: false + is_print_traceback: true + +hook_test: + apisix: + - http_access_phase + +#END +--- request +GET /hello +--- more_headers +Host: foo.com +--- response_body +hello world +--- error_log +call require("apisix").http_access_phase() call stack:stack traceback: