Skip to content

feat(debug): add print_traceback for debugging - #12777

Closed
xuruidong wants to merge 3 commits into
apache:masterfrom
xuruidong:print_traceback
Closed

feat(debug): add print_traceback for debugging#12777
xuruidong wants to merge 3 commits into
apache:masterfrom
xuruidong:print_traceback

Conversation

@xuruidong

@xuruidong xuruidong commented Nov 25, 2025

Copy link
Copy Markdown
Contributor

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

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)

@dosubot dosubot Bot added size:M This PR changes 30-99 lines, ignoring generated files. enhancement New feature or request labels Nov 25, 2025

@Baoyuantop Baoyuantop left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please describe the PR so that maintainers understand its intent.

@Baoyuantop

Copy link
Copy Markdown
Contributor

Hi @xuruidong, I'll mark the PR as draft for now. You can change the status back after you add the PR description.

@Baoyuantop
Baoyuantop marked this pull request as draft December 3, 2025 03:16
@xuruidong

Copy link
Copy Markdown
Contributor Author

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

@Baoyuantop Baoyuantop added the wait for update wait for the author's response in this issue/PR label Dec 24, 2025
@xuruidong
xuruidong marked this pull request as ready for review January 11, 2026 09:18
@xuruidong
xuruidong requested a review from Baoyuantop January 11, 2026 09:19
@Baoyuantop
Baoyuantop requested a review from Copilot March 11, 2026 09:52

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.yaml hook schema to support hook_conf.is_print_traceback.
  • Emit debug.traceback() in hook wrapper when is_print_traceback is 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.

Comment thread apisix/debug.lua
Comment on lines +201 to +202
log[log_level]("call require(\"", file_path, "\").", fun_name,
"() call stack:", debug.traceback())

Copilot AI Mar 11, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Suggested change
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)

Copilot uses AI. Check for mistakes.
Comment thread apisix/debug.lua
Comment on lines 77 to 84
},
is_print_return_value = {
type = "boolean",
},
is_print_traceback = {
type = "boolean",
},
}

Copilot AI Mar 11, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.

@moonming moonming left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. Is this meant for development/debugging only, or should it be available in production?
  2. If development-only, should it be behind a debug flag or configuration option?
  3. How does it interact with existing error logging and the error-log-logger plugin?

Could you clarify the use case and add appropriate guards (e.g., only enabled in debug mode)? Thank you!

@Baoyuantop

Copy link
Copy Markdown
Contributor

Hi @xuruidong, following up on the previous review comments. Please let us know if you have any updates. Thank you.

@github-actions

Copy link
Copy Markdown

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.

@github-actions github-actions Bot added the stale label Jun 12, 2026
@github-actions

Copy link
Copy Markdown

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.

@github-actions github-actions Bot closed this Jul 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request size:M This PR changes 30-99 lines, ignoring generated files. stale wait for update wait for the author's response in this issue/PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants