feat(debug): add print_traceback for debugging - #12777
Conversation
Baoyuantop
left a comment
There was a problem hiding this comment.
Please describe the PR so that maintainers understand its intent.
|
Hi @xuruidong, I'll mark the PR as draft for now. You can change the status back after you add the PR description. |
ok,I will take care of this PR later |
There was a problem hiding this comment.
Pull request overview
Adds a new debug-mode hook option to emit Lua stack traces when invoking hooked functions, improving observability when diagnosing execution flow in APISIX.
Changes:
- Extend
conf/debug.yamlhook schema to supporthook_conf.is_print_traceback. - Emit
debug.traceback()in hook wrapper whenis_print_tracebackis enabled. - Add a test case covering traceback logging for a statically enabled hook.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
apisix/debug.lua |
Adds schema support and hook-time logging of stack trace via debug.traceback(). |
t/debug/hook.t |
Adds a regression test asserting traceback output is logged when enabled. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| log[log_level]("call require(\"", file_path, "\").", fun_name, | ||
| "() call stack:", debug.traceback()) |
There was a problem hiding this comment.
The log output currently concatenates the prefix "() call stack:" directly with debug.traceback()'s default leading text ("stack traceback:"), producing "call stack:stack traceback:" with no separator and a redundant label. Consider using debug.traceback(<message>, <level>) to embed the message and add a newline/space separator, and set the level to skip the hook wrapper frames (e.g., start traceback at the original caller rather than mt.__call).
| log[log_level]("call require(\"", file_path, "\").", fun_name, | |
| "() call stack:", debug.traceback()) | |
| local msg = "call require(\"" .. file_path .. "\")." .. fun_name .. "() call stack:" | |
| local tb = debug.traceback(msg, 3) | |
| log[log_level](tb) |
| }, | ||
| is_print_return_value = { | ||
| type = "boolean", | ||
| }, | ||
| is_print_traceback = { | ||
| type = "boolean", | ||
| }, | ||
| } |
There was a problem hiding this comment.
A new debug.yaml option hook_conf.is_print_traceback is introduced in the schema, but the debug-mode documentation tables/examples still only describe is_print_input_args and is_print_return_value. Please update the docs (both EN/ZH) and the sample configuration to include this new key so users can discover and configure it correctly.
moonming
left a comment
There was a problem hiding this comment.
Hi @xuruidong, thank you for the debug traceback feature!
While print_traceback can be useful for debugging, I'd like to understand the intended use case better:
- Is this meant for development/debugging only, or should it be available in production?
- If development-only, should it be behind a debug flag or configuration option?
- How does it interact with existing error logging and the
error-log-loggerplugin?
Could you clarify the use case and add appropriate guards (e.g., only enabled in debug mode)? Thank you!
|
Hi @xuruidong, following up on the previous review comments. Please let us know if you have any updates. Thank you. |
|
This pull request has been marked as stale due to 60 days of inactivity. It will be closed in 4 weeks if no further activity occurs. If you think that's incorrect or this pull request should instead be reviewed, please simply write any comment. Even if closed, you can still revive the PR at any time or discuss it on the dev@apisix.apache.org list. Thank you for your contributions. |
|
This pull request/issue has been closed due to lack of activity. If you think that is incorrect, or the pull request requires review, you can revive the PR at any time. |
Description
This enhancement improves APISIX's debugging capabilities by providing developers with comprehensive call stack visibility for efficient problem diagnosis.
Which issue(s) this PR fixes:
Fixes #
Checklist