Skip to content

Commit 5511204

Browse files
s-noghabiThe tunix Authors
authored andcommitted
make async timeline failure log errors
PiperOrigin-RevId: 889305628
1 parent 8ea9ef7 commit 5511204

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

tests/perf/experimental/timeline_test.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,8 +234,19 @@ def fail_wait(waitlist, success, failure):
234234

235235
self.mock_async_wait.side_effect = fail_wait
236236

237-
with self.assertRaisesRegex(RuntimeError, "failed"):
238-
t.span("failed", 1.0, ["wait"])
237+
with mock.patch.object(timeline.logging, "error") as mock_log_error:
238+
t.span("failed_op", 1.0, ["wait"])
239+
# Exception is caught and logged, no exception is raised to the caller.
240+
mock_log_error.assert_called_once()
241+
args, kwargs = mock_log_error.call_args
242+
format_str, name, span_id, err = args
243+
self.assertEqual(format_str, "Timeline span '%s' (id=%d) failed: %s")
244+
self.assertEqual(name, "failed_op")
245+
self.assertEqual(span_id, 0)
246+
self.assertIsInstance(err, RuntimeError)
247+
self.assertEqual(str(err), "failed")
248+
self.assertIn("exc_info", kwargs)
249+
self.assertIsInstance(kwargs["exc_info"], RuntimeError)
239250

240251
def test_wait_pending_spans_clears_threads(self):
241252
t = timeline.AsyncTimeline("test_tl", 0.0)

tunix/perf/experimental/timeline.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,10 @@ def on_success() -> None:
262262
def on_failure(e: Exception) -> None:
263263
# TODO(noghabi):Capture the span even if it fails, but add a tag that it
264264
# failed and process accordingly.
265-
raise e
265+
# Metrics are best effort and should not raise exceptions.
266+
logging.error(
267+
"Timeline span '%s' (id=%d) failed: %s", name, span_id, e, exc_info=e
268+
)
266269

267270
if not waitlist:
268271
on_success()

0 commit comments

Comments
 (0)