Skip to content

structlog: migrate application code to better logging #8705

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Nov 29, 2021

Conversation

humitos
Copy link
Member

@humitos humitos commented Nov 23, 2021

Initial work to migrate our application to structlog for better logging, making
them compatible with New Relic's integration.

There is more work that can be done here to make it better. For example, more
usage of log.bind to avoid repetition. Besides, rewriting some log messages and
reducing them to have more Canonical Log
Lines (https://www.structlog.org/en/stable/logging-best-practices.html#canonical-log-lines)
instead.

NOTE: this PR does not really require an extensive review. It's mostly just a search&replace. As far as the tests are passing, it should be fine to merge.

The migration steps followed are described in #8689. Also note that this PR is based on that one.

Screenshot_2021-11-23_19-01-00

@humitos humitos requested a review from a team November 23, 2021 14:15
@humitos humitos force-pushed the humitos/migrate-to-structlog branch 4 times, most recently from d546298 to 8eb7800 Compare November 23, 2021 16:27
Initial work to migrate our application to structlog for better logging, making
them compatible with New Relic's integration.

There are more work that can be done here to make it better. For example, more
usage of `log.bind` to avoid repetition. Besides, rewriting some log message and
reduce them to have more Canonical Log
Lines (https://www.structlog.org/en/stable/logging-best-practices.html#canonical-log-lines)
instead.
@humitos humitos force-pushed the humitos/migrate-to-structlog branch from 8eb7800 to 1110839 Compare November 23, 2021 16:47
Logs coming from `logging.getLogger` (from other applications) have the same
structure that the ones logged by us via `structlog`.
@humitos humitos force-pushed the humitos/migrate-to-structlog branch from 84ff22d to 9b261ab Compare November 23, 2021 18:54
Use a custom renderer to match the structure we want:

```
%programname[%processid] [%level] %message [%logger:%linenumber] %structureddata
```

By default, rsyslog will prepend

```
%timestamp %hostname
```

and it will look exactly as we want.
@humitos humitos mentioned this pull request Nov 29, 2021
Copy link
Member

@ericholscher ericholscher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a huge change that involved core functionality and massive logging changes, which I was hoping to avoid. I am going to approve and merge it because I assume it's well-tested, but this PR is basically impossible to review as it currently is without a huge amount of time unfortunately.

I would have loved to at least see the code changes and the mass migration done in different PR's or some other way to make it reviewable.


def __exit__(self, exc, value, tb):
log.bind(project_slug=self.name)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this unbind it, since we're also setting this on __enter__? Could definitely use a comment.

Copy link
Member Author

@humitos humitos Nov 30, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ericholscher ericholscher merged commit 18a8d71 into humitos/embed-api-log Nov 29, 2021
@ericholscher ericholscher deleted the humitos/migrate-to-structlog branch November 29, 2021 20:41
@agjohnson agjohnson restored the humitos/migrate-to-structlog branch November 29, 2021 21:28
@stsewd stsewd deleted the humitos/migrate-to-structlog branch October 11, 2023 21:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants