-
Notifications
You must be signed in to change notification settings - Fork 0
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
Filter asset requests from Hapi-pino logs #16
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Cruikshanks
added
the
housekeeping
Refactoring, tidying up or other work which supports the project
label
Nov 4, 2022
Cruikshanks
force-pushed
the
filter-asset-requests-from-logs
branch
from
November 6, 2022 23:38
9e73894
to
ec43eaa
Compare
Jozzey
previously approved these changes
Nov 7, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Our current hapi-pino configuration is based on what we needed for the [sroc-charging-module-api](https://github.com/DEFRA/sroc-charging-module-api). But as an API it never had to worry about assets and requests from the browser for them. As we use this app, we're seeing multiple log entries per page. This is because it's logging both the main request plus one for each asset used by the page. Below is an example of what we see. Bear in mind that we have only listed the top level entry. Each one is 41 lines long (when working locally) because the logger details both the request and response. ```text [09:41:06.763] INFO (17542): [response] get /service-status 200 (1138ms) [09:41:06.871] INFO (17542): [response] get /assets/stylesheets/application.css 200 (72ms) [09:41:06.873] INFO (17542): [response] get /assets/all.js 200 (64ms) [09:41:06.893] INFO (17542): [response] get /assets/images/govuk-crest.png 200 (8ms) [09:41:06.926] INFO (17542): [response] get /assets/fonts/light-94a07e06a1-v2.woff2 200 (19ms) [09:41:06.928] INFO (17542): [response] get /assets/fonts/bold-b542beb274-v2.woff2 200 (18ms) [09:41:07.032] INFO (17542): [response] get /assets/images/favicon.ico 200 (6ms) ``` Our primary reason for using hapi-pino is to reduce the noise in our logs so we can find and focus on what's important. This change updates the hapi-pino filtering so we only log the main requests. It will include an option to switch back on asset logging, just in case we ever have issues and need that extra detail.
This all works and gives us the outcome we want. Next we'll look at refactoring it to match our conventions and make it easier to test.
This makes it easier to test and makes the plugin code clearer.
We need somewhere to put our config for whether to include asset requests in the log. We already have a setting to control whether the log should record anything when running in test. So, putting these together makes the most sense. Having done then, we concluded this isn't really test config, but log config hence we have renamed the file.
There is a possiblity we need to investigate an issue with assets in the future, for which logging will be incredibly useful. So, we add a config option that allows us to quick configure the repo to start logging asset requests again.
Cruikshanks
force-pushed
the
filter-asset-requests-from-logs
branch
from
November 7, 2022 22:34
30a29d8
to
7d32269
Compare
Beckyrose200
approved these changes
Nov 7, 2022
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Our current hapi-pino configuration is based on what we needed for the sroc-charging-module-api. But as an API it never had to worry about assets and requests from the browser for them.
As we use this app, we're seeing multiple log entries per page. This is because it's logging both the main request plus one for each asset used by the page. Below is an example of what we see. Bear in mind that we have only listed the top-level entry. Each one is 41 lines long (when working locally) because the logger details both the request and response.
Our primary reason for using hapi-pino is to reduce the noise in our logs so we can find and focus on what's important. This change updates the hapi-pino filtering so we only log the main requests. It will include an option to switch back on asset logging, just in case we ever have issues and need that extra detail.
** Notes
We needed somewhere to put our config for whether to include asset requests in the log. We already have a setting to control whether the log should record anything when running in
test
. So, putting these together made the most sense.Having done that, we concluded this wasn't really test config anymore, but log config. Hence we renamed the file.