1- PEP: 9999
1+ PEP: 829
22Title: Add timestamps to exceptions and tracebacks
33Author: Gregory P. Smith <greg@krypto.org>
44PEP-Delegate:
@@ -14,9 +14,9 @@ Abstract
1414========
1515
1616This PEP adds an optional ``__timestamp_ns__ `` attribute to ``BaseException ``
17- that records when the exception was instantiated. When enabled via environment
18- variable or command-line flag, formatted tracebacks display this timestamp
19- alongside the exception message.
17+ that records when the exception was instantiated with no observable overhead.
18+ When enabled via environment variable or command-line flag, formatted
19+ tracebacks display this timestamp alongside the exception message.
2020
2121
2222Motivation
@@ -27,9 +27,9 @@ propagate multiple unrelated exceptions simultaneously. When debugging these,
2727or when correlating exceptions with external logs and metrics, knowing *when *
2828each exception occurred is often as important as knowing *what * occurred.
2929
30- Currently there is no standard way to obtain this information. Developers must
31- manually add timing to exception messages or rely on logging frameworks, which
32- is inconsistent and error-prone.
30+ Currently there is no standard way to obtain this information. Python authors
31+ must manually add timing to exception messages or rely on logging frameworks,
32+ which can be costly and is inconsistently done and error-prone.
3333
3434Consider an async service that fetches data from multiple backends concurrently
3535using ``asyncio.TaskGroup ``. When several backends fail, the resulting
@@ -91,8 +91,9 @@ With ``PYTHON_TRACEBACK_TIMESTAMPS=iso``, the output becomes:
9191
9292 The timestamps immediately reveal that the order validation failed first
9393(at .142s), while the recommendation service was the slowest at 2.3 seconds.
94- They can also be correlated with metrics dashboards, load balancer logs, or
95- traces from other services to build a complete picture of the incident.
94+ That could also be correlated with metrics dashboards, load balancer logs, or
95+ traces from other services or even logs from the program itself to build a
96+ complete picture.
9697
9798
9899Rationale
@@ -124,7 +125,7 @@ Control Flow Exceptions
124125To avoid performance impact on normal control flow, timestamps are **not **
125126collected for ``StopIteration `` or ``StopAsyncIteration `` even when the feature
126127is enabled. These exceptions are raised at extremely high frequency during
127- iteration; the check uses C type pointer identity (not ``isinstance ``) and adds
128+ iteration; the check uses C type pointer identity (not ``isinstance ``) for
128129negligible overhead.
129130
130131Configuration
@@ -228,6 +229,18 @@ GitHub Actions runs to maintain coverage, most projects are unlikely to
228229have the feature enabled while running their test suites.
229230
230231
232+ Performance Measurements
233+ ========================
234+
235+ The pyperformance suite has been run on the merge base, on the PR branch with
236+ the feature disabled, and on the PR branch with the feature enabled in both
237+ ``ns `` and ``iso `` modes.
238+
239+ TODO(@gpshead): summarize results of the most recent run here.
240+
241+ TODO(@gpshead): Do another run with the feature enabled but without the StopIteration special case to demonstrate why that choice was made.
242+
243+
231244Security Implications
232245=====================
233246
0 commit comments