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

Include exception type and reason in structured logging json #10209

@anoadragon453

Description

@anoadragon453

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:

# 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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    T-EnhancementNew features, changes in functionality, improvements in performance, or user-facing enhancements.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions