Include exception type and reason in structured logging json
See original GitHub issueCurrently 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:
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).
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:6 (5 by maintainers)
The
logger
call in question was this one:https://github.com/matrix-org/synapse/blob/e9f2ad86034d27068941379f678e19bf280ed308/synapse/metrics/background_process_metrics.py#L216-L219
Which resulted in:
Which doesn’t seem to include any useful exception information… unless it’s getting lost in this specific instance?
Also an issue with request handling failures:
This code block here: https://github.com/matrix-org/synapse/blob/4b965c862dc66c0da5d3240add70e9b5f0aa720b/synapse/http/server.py#L93-L98
precise output:
structured output:
without a backtrace