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

Commit

Permalink
Improve stacktraces from exceptions in background processes (#7808)
Browse files Browse the repository at this point in the history
use `Failure()` to fish out the real exception.
  • Loading branch information
richvdh authored Jul 9, 2020
1 parent 08c5181 commit 8ca39bd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
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

0 comments on commit 8ca39bd

Please sign in to comment.