I am proposing to add recent_first
and show_lines
parameters to traceback
APIs.
Please review its design and implementation.
- Previous discussion: Shorter and reversed format for traceback
- PR: gh-135751: traceback: add recent_first and show_lines parameter by methane · Pull Request #135752 · python/cpython · GitHub
- Issue: traceback: add `recent_first` and `show_lines` parameters · Issue #135751 · python/cpython · GitHub
Current traceback format (recent call last, show each lines) is optimized for console.
It is not good for observability backends. For example, this is the list of stacktrace representations in Open Telemetry conventions. All languages except Python uses “recent call first, no source code lines” format.
My design decisions:
- Fullpath of source code looks too long, but this PR focuses only order and source lines.
- Default values of both options are same to existing behavior.
- I chose the name
recent_first=False
becausereverse
norreversed_order
are not descriptive. Since we seeTraceback (most recent call last)
everyday, “recent call (first | last)” would more descriptive. I removed “call” for shorter name.recent_last=True
would also work, and I don’t have a strong preference between the two. - I chose the name
show_lines
because of consistency with:FrameSummary.line
StackSummary.extract(..., lookup_lines, ...)
format_exception_only(..., show_group, ...)