Skip to content
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 7 commits into from
Nov 7, 2022

Conversation

Cruikshanks
Copy link
Member

@Cruikshanks Cruikshanks commented Nov 4, 2022

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.

[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.

** Notes

  • Rename test config

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.

@Cruikshanks Cruikshanks added the housekeeping Refactoring, tidying up or other work which supports the project label Nov 4, 2022
@Cruikshanks Cruikshanks self-assigned this Nov 4, 2022
@Cruikshanks Cruikshanks force-pushed the filter-asset-requests-from-logs branch from 9e73894 to ec43eaa Compare November 6, 2022 23:38
@Cruikshanks Cruikshanks marked this pull request as ready for review November 6, 2022 23:43
Jozzey
Jozzey previously approved these changes Nov 7, 2022
Copy link
Contributor

@Jozzey Jozzey left a 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.
Copy link
Contributor

@Beckyrose200 Beckyrose200 left a comment

Choose a reason for hiding this comment

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

@Cruikshanks Cruikshanks merged commit 2d904c0 into main Nov 7, 2022
@Cruikshanks Cruikshanks deleted the filter-asset-requests-from-logs branch November 7, 2022 23:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
housekeeping Refactoring, tidying up or other work which supports the project
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants