There's a new tiny package which provides a python traceback logging in
the journal for python processes. It's very similar to the existing
handler provided by abrt, it also installs itself as sys.excepthook
using a .pth file, but instead of communicating with abrt, it talks to
systemd-coredump directly.
The advantage is that it provides a backtrace in the journal (in
red!), which coredumpctl list/info know about. Various stuff that
systemd-coredump gathers (fdinfo, cgroups, mounts, unit, slices,
limits, uid, gid, etc) are recorded. No call stack of the process is
gathered though, just the python backtrace.
I'm not 100% convinced that this will be useful myself. If you have
Python services, maybe. I'd be interested to hear what people think
about this.
To try it out:
1. make sure you're on systemd 233 (currently only rawhide or F26)
2. dnf install python3-systemd-coredump (or python2-system-coredump)
3. uninstall or disable abrt
(two separate things matter:
- systemd-coredump-python checks if systemd-coredump is configured
in sysctl kernel.core_pattern, and does nothing if not,
- abrt-addon-python3 installs its handler unconditionally and
exclusively.
So instead of removing abrt it is enough to:
systemctl stop abrt\* && rm /usr/lib64/python*/site-packages/abrt.pth
This conflict should be temporary, the patch to make the abrt
handler non-exclusive should be trivial.)
4. run a python script that throws an exception
e.g. python3 /usr/lib/python3.5/site-packages/systemd_coredump_exception_handler.py,
this should print a traceback to stdout
5. check 'coredumpctl' and 'journalctl' output, a backtrace should be
logged.
$ coredumpctl info -1
PID: 29688 (python3)
UID: 1000 (zbyszek)
GID: 1000 (zbyszek)
Reason: ZeroDivisionError
Timestamp: Tue 2017-03-14 22:41:41 EDT (6min ago)
Command Line: python3 /usr/lib/python3.5/site-packages/systemd_coredump_exception_handler.py
Executable: /usr/bin/python3.5
Control Group: /user.slice/user-1000.slice/user(a)1000.service/gnome-terminal-server.service
Unit: user(a)1000.service
User Unit: gnome-terminal-server.service
Slice: user-1000.slice
Owner UID: 1000 (zbyszek)
Boot ID: b3ca39ca747e4cd896e9e5fbb0e07f5e
Machine ID: ad18f69b80264b52bb3b766240742383
Hostname: fedora
Storage: none
Message: Process 29688 (/usr/lib/python3.5/site-packages/systemd_coredump_exception_handler.py)
of user zbyszek failed with ZeroDivisionError: division by zero
Traceback (most recent call last):
File "/usr/lib/python3.5/site-packages/systemd_coredump_exception_handler.py", line 165, in <module>
g()
File "/usr/lib/python3.5/site-packages/systemd_coredump_exception_handler.py", line 164, in g
f()
File "/usr/lib/python3.5/site-packages/systemd_coredump_exception_handler.py", line 162, in f
div0 = 1 / 0
ZeroDivisionError: division by zero
Local variables in innermost frame:
h=<function f at 0x7f3eb38f3400>
a=3
Zbyszek