PEP 829: Add timestamps to exceptions and tracebacks#4592
Draft
gpshead wants to merge 12 commits intopython:mainfrom
Draft
PEP 829: Add timestamps to exceptions and tracebacks#4592gpshead wants to merge 12 commits intopython:mainfrom
gpshead wants to merge 12 commits intopython:mainfrom
Conversation
This draft PEP proposes adding optional timestamps to Python exception objects that can be displayed in tracebacks. Based on CPython PR #129337 by Gregory P. Smith. The feature adds a __timestamp_ns__ attribute to BaseException and allows configuration via environment variables or command-line options. This is particularly useful for debugging async applications with exception groups and distributed systems. 🤖 Generated with Claude Code (https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Added two important open issues to the PEP: 1. Whether to always collect timestamps unconditionally (performance testing shows it's cheap) and the implications for pickle size and cross-version compatibility testing 2. Configuration of control flow exception exclusions (StopIteration, AsyncStopIteration) and whether subclasses should be included, noting the performance constraints of the hot path 🤖 Generated with Claude Code (https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Added two new sections to address questions raised at core team sprint: 1. "Why Exception Groups Need Timestamps" - Explains that while exception groups are conceptually unrelated, in practice they have important temporal relationships for debugging causality, performance analysis, and correlation with external observability tools. 2. "Why Not Use .add_note() When Catching?" - Details six key drawbacks of using add_note() instead: not all exceptions are caught, timing accuracy issues, inconsistent application, performance overhead, complexity burden, and loss of original timing information. Key insight: When an exception occurs is intrinsic, immutable information that should be captured at the source, not added later by consumers. 🤖 Generated with Claude Code (https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
… need Based on feedback from @picnixz about Sphinx's Skip exception and other projects using exceptions for control flow: 1. Renamed "Special Cases" to "Control Flow Exceptions" for clarity 2. Added acknowledgment that other projects need this configurability 3. Deferred specific API design to open issues 4. Updated Open Issue python#5 with key challenges: - API design options (env var vs Python API) - Performance constraints in the hot path - Subclass handling complexity - Whether to expand the default exclusion list The PEP now acknowledges the need for configurability while leaving the specific implementation approach as an open question requiring careful API design and performance testing. 🤖 Generated with Claude Code (https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
This comment was marked as spam.
Align the PEP with the current reference implementation, resolve all open issues, and rewrite for conciseness and natural tone. Implementation alignment: - Fix type description to int64_t, fix StopAsyncIteration name - Document pickle format (2-tuple when disabled, 3-tuple when enabled) - Document colorized output, control flow check uses C pointer identity - Resolve all open issues into Rejected Ideas Writing improvements: - Cut from ~500 to ~300 lines by removing redundant subsections - Rewrite Motivation: delete "Why Exception Groups Need Timestamps", move .add_note() comparison to Rejected Ideas, trim example analysis - Convert numbered bold lists to prose throughout - Add Maintenance Burden section with test suite impact data - Remove non-ASCII characters and remaining LLM-isms - Security Implications: None (opt-in, disabled by default) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
6832465 to
21686cf
Compare
This comment was marked as resolved.
This comment was marked as resolved.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The PEPs and CPython PR are already linked inline throughout the text. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PEP adds an optional
__timestamp_ns__attribute toBaseExceptionthat records when the exception was instantiated. When enabled viaPYTHON_TRACEBACK_TIMESTAMPSor-X traceback_timestamps, formatted tracebacks display the timestamp alongside the exception message.This feature was presented and discussed at the September 2025 Core Team sprint in Cambridge, UK. The reference implementation is CPython PR #129337.
Basic requirements (all PEP Types)
pep-NNNN.rst), PR title (PEP 123: <Title of PEP>) andPEPheaderAuthororSponsor, and formally confirmed their approvalAuthor,Status(Draft),TypeandCreatedheaders filled out correctlyPEP-Delegate,Topic,RequiresandReplacesheaders completed if appropriate.github/CODEOWNERSfor the PEPStandards Track requirements
Python-Versionset to valid (pre-beta) future Python version, if relevantDiscussions-ToandPost-History📚 Documentation preview 📚: https://pep-previews--4592.org.readthedocs.build/