Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Improve stacktraces from exceptions in background processes #7808

Merged
merged 1 commit into from
Jul 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/7808.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Improve stacktraces from exceptions in background processes.
10 changes: 9 additions & 1 deletion synapse/metrics/background_process_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from prometheus_client.core import REGISTRY, Counter, Gauge

from twisted.internet import defer
from twisted.python.failure import Failure

from synapse.logging.context import LoggingContext, PreserveLoggingContext

Expand Down Expand Up @@ -212,7 +213,14 @@ def run():

return (yield result)
except Exception:
logger.exception("Background process '%s' threw an exception", desc)
# failure.Failure() fishes the original Failure out of our stack, and
# thus gives us a sensible stack trace.
f = Failure()
logger.error(
"Background process '%s' threw an exception",
desc,
exc_info=(f.type, f.value, f.getTracebackObject()),
)
finally:
_background_process_in_flight_count.labels(desc).dec()

Expand Down