PEP 830: Add timestamps to exceptions and tracebacks

The SC has discussed and while we are generally positive about PEP 830 - Add timestamps to exceptions and tracebacks, we have decided to defer making a decision on this PEP until Python 3.16. We have feedback on collection and on the opt-in/display story that we’d like to see worked through before we make a decision.

On the collection:

  • The current performance numbers do not cover Windows or shared-library configurations (which may see significantly more overhead). We’d like to see numbers for those environments incorporated into the PEP so we can better evaluate the overhead claim across platforms.
  • Pickle output depends on the timestamp collection state, which we find awkward. We’d prefer an opt-out, either by not collecting, or by not pickling the timestamp attribute even when collection is enabled.

On opt-in and display:

  • The PEP appeals to CPython convention to justify silent-ignore on invalid env var values, but that convention is really for boolean toggles (e.g. PYTHONFAULTHANDLER, PYTHONDEVMODE) and not for enum-shaped flags (e.g. PYTHON_GIL, PYTHON_FROZEN_MODULES, PYTHONTRACEMALLOC, PYTHON_CPU_COUNT, PYTHONHASHSEED). Enum-shaped flags by and large fail-fatal on invalid values, and PYTHON_TRACEBACK_TIMESTAMPS should follow the convention of that peer group. This behavior should also be aligned across the env var and -X paths to avoid a confusing user experience and bifurcation of documentation.
  • PYTHON_TRACEBACK_TIMESTAMPS and -X traceback_timestamps= should accept one value per meaning. Each precision option should have a single canonical string (e.g. ns, us, ms, iso), with an explicit off for disabled. Equivalents like empty, 0, and 1 should be rejected as invalid rather than silently aliased to one of the canonical values.
  • The current proposed timestamp suffix appears on the message line in formatted traceback output and is per-occurrence, which means tooling that captures stderr or formatted tracebacks and matches on the message line sees a different string for every exception instance. The discussion thread raised header-line placement as an alternative that avoids this. We don’t think message-line placement is necessarily wrong, but the PEP should further justify the choice with a clear rationale and close out the open issue regarding display location. Further, placing the timestamp at the end of the line obscures it in ways that can be difficult to see.
  • Opt-out for doctest printing will likely break code and is backward incompatible. This is because doctests can be very sensitive to display output. We’d prefer an opt-in flag, e.g. doctest.INCLUDE_EXCEPTION_TIMESTAMPS which are not enabled by default.
  • Similarly test.support.force_no_traceback_timestamps should probably be enabled by default, possibly with a differently named flag to enable traceback timestamps in the stdlib test suite.

Thanks again for your work on this PEP, we look forward to discussing again with revisions.

8 Likes