-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Include exception type and reason in structured logging json #10209
Description
Currently when structured logging is enabled (using either the JsonFormatter
or TerseJsonFormatter
), logger.exception
lines don't include a traceback nor any exception information at all (other than what's presented in the string passed to logger.exception
.
This is due to us ignoring the exc_text
and exc_info
attributes of the log record when during formatting:
synapse/synapse/logging/_terse_json.py
Lines 23 to 31 in 18edc9a
# The properties of a standard LogRecord that should be ignored when generating | |
# JSON logs. | |
_IGNORED_LOG_RECORD_ATTRIBUTES = { | |
"args", | |
"asctime", | |
"created", | |
"exc_info", | |
# exc_text isn't a public attribute, but is used to cache the result of formatException. | |
"exc_text", |
While it's not quite feasible to include full tracebacks in structured logging (one should use a tool like Sentry.io for that), it may be useful to include the exception type ((i.e psycopg2.OperationalError
) and text (i.e FATAL: sorry, too many clients already
) as structured fields. This will give sysadmins a clue as to what might be going wrong, whereas Sentry is useful for pointing out the line where the issue occurred (and thus where developers may be able to go in and fix the issue).