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

Add custom serializers to improve app logging #1655

Merged
merged 5 commits into from
Jan 27, 2025
Merged

Conversation

Cruikshanks
Copy link
Member

We've completed a number of changes to our logging in the time we have been on the project.

Generally, we 'go to the logs' when an issue has been reported in production, and we need to figure out what has happened.

Therefore, we constantly balance, ensuring we have all the necessary information while excluding noise.

For reasons (😩😬), we've had to deal with several live issues in a short space of time recently. Having dealt with them, we've reflected on what we are currently logging.

We conclude that it is still too much!

For example, we are outputting this on every GET request.

5|system  | [15:19:25.232] INFO (1313): [response] get /bill-runs/review/460a2180-34c7-46aa-b72d-dfdb5b6c5472 200 (104ms)
5|system  |     req: {
5|system  |       "id": "1737904765128:9bc56d13c48b:1313:m6drmcd1:10001",
5|system  |       "method": "get",
5|system  |       "url": "/bill-runs/review/460a2180-34c7-46aa-b72d-dfdb5b6c5472",
5|system  |       "query": {},
5|system  |       "headers": {
5|system  |         "connection": "keep-alive",
5|system  |         "cache-control": "max-age=0",
5|system  |         "upgrade-insecure-requests": "1",
5|system  |         "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36",
5|system  |         "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
5|system  |         "sec-fetch-site": "same-origin",
5|system  |         "sec-fetch-mode": "navigate",
5|system  |         "sec-fetch-user": "?1",
5|system  |         "sec-fetch-dest": "document",
5|system  |         "sec-ch-ua": "\"Not A(Brand\";v=\"8\", \"Chromium\";v=\"132\", \"Google Chrome\";v=\"132\"",
5|system  |         "sec-ch-ua-mobile": "?0",
5|system  |         "sec-ch-ua-platform": "\"macOS\"",
5|system  |         "referer": "http://localhost:8008/system/bill-runs/review/460a2180-34c7-46aa-b72d-dfdb5b6c5472",
5|system  |         "accept-encoding": "gzip, deflate, br, zstd",
5|system  |         "accept-language": "en-GB,en;q=0.9,en-US;q=0.8",
5|system  |         "cookie": "imagine_a_long_string_made_up_of_a_mish_mash_of_letters_and_numbers_because_it_is_encrypted",
5|system  |         "x-forwarded-for": "172.18.0.1",
5|system  |         "x-forwarded-port": "57172",
5|system  |         "x-forwarded-proto": "http",
5|system  |         "x-forwarded-host": "localhost:8008",
5|system  |         "host": "localhost:8013"
5|system  |       },
5|system  |       "remoteAddress": "127.0.0.1",
5|system  |       "remotePort": 56298
5|system  |     }
5|system  |     res: {
5|system  |       "statusCode": 200,
5|system  |       "headers": {
5|system  |         "strict-transport-security": "max-age=15768000",
5|system  |         "x-frame-options": "DENY",
5|system  |         "x-xss-protection": "0",
5|system  |         "x-download-options": "noopen",
5|system  |         "x-content-type-options": "nosniff",
5|system  |         "cache-control": "no-cache",
5|system  |         "set-cookie": [
5|system  |           "wrlsSession=Fe26.imagine_a_long_string_made_up_of_a_mish_mash_of_letters_and_numbers_because_it_is_encrypted; Secure; HttpOnly; SameSite=Lax; Path=/"
5|system  |         ],
5|system  |         "content-type": "text/html; charset=utf-8",
5|system  |         "vary": "accept-encoding",
5|system  |         "content-encoding": "gzip"
5|system  |       }
5|system  |     }
5|system  |     responseTime: 104

However, from our experience of handling issues, all we look at is

  • req: - the ID (can be handy to trace transactions), the method, and the URL
  • res: - the status code (did it succeed or error)

The rest is pure noise. On the other hand, additional data would be handy to see, for example, the payload on POST requests.

This change updates our config for Hapi-pino to tell it to add the following to the logs

  • the payload
  • any query params
  • any path params

It also implements our own serializers, which take the req and res objects returned by pino-std-serializers and transform them to only include the properties we care about. With these changes, our log output now looks like this.

5|system  | [16:33:17.125] INFO (1333): [response] post /bill-runs/review/460a2180-34c7-46aa-b72d-dfdb5b6c5472 302 (58ms)
5|system  |     req: {
5|system  |       "id": "1737909197067:9bc56d13c48b:1333:m6du9e83:10000",
5|system  |       "method": "get",
5|system  |       "url": "/bill-runs/review/460a2180-34c7-46aa-b72d-dfdb5b6c5472",
5|system  |       "query": {}
5|system  |     }
5|system  |     payload: {
5|system  |       "filterIssues": "aggregate-factor",
5|system  |       "filterLicenceStatus": "review"
5|system  |     }
5|system  |     queryParams: {}
5|system  |     pathParams: {
5|system  |       "billRunId": "460a2180-34c7-46aa-b72d-dfdb5b6c5472"
5|system  |     }
5|system  |     res: {
5|system  |       "statusCode": 302
5|system  |     }
5|system  |     responseTime: 58
5|system  | [16:33:17.235] INFO (1333): [response] get /bill-runs/review/460a2180-34c7-46aa-b72d-dfdb5b6c5472 200 (99ms)
5|system  |     req: {
5|system  |       "id": "1737909197135:9bc56d13c48b:1333:m6du9e83:10001",
5|system  |       "method": "get",
5|system  |       "url": "/bill-runs/review/460a2180-34c7-46aa-b72d-dfdb5b6c5472",
5|system  |       "query": {}
5|system  |     }
5|system  |     queryParams: {}
5|system  |     pathParams: {
5|system  |       "billRunId": "460a2180-34c7-46aa-b72d-dfdb5b6c5472"
5|system  |     }
5|system  |     res: {
5|system  |       "statusCode": 200
5|system  |     }
5|system  |     responseTime: 99

We've completed a [number of changes to our logging](https://github.com/DEFRA/water-abstraction-team/issues?q=is%3Aissue%20state%3Aclosed%20log) in the time we have been on the project.

Generally, we 'go to the logs' when an issue has been reported in `production` and we need to figure out what has happened.

Therefore, we are always balancing ensuring we have all the information we need whilst excluding anything that is just noise.

For reasons (😩😬) we've had to deal with a number of live issues in a short space of time recently. Having now dealt with them, we've reflected on what exactly we are currently logging.

Our conclusion is that it is still too much!

This, for example, is what we are outputting on every `GET` request.

```text
5|system  | [15:19:25.232] INFO (1313): [response] get /bill-runs/review/460a2180-34c7-46aa-b72d-dfdb5b6c5472 200 (104ms)
5|system  |     req: {
5|system  |       "id": "1737904765128:9bc56d13c48b:1313:m6drmcd1:10001",
5|system  |       "method": "get",
5|system  |       "url": "/bill-runs/review/460a2180-34c7-46aa-b72d-dfdb5b6c5472",
5|system  |       "query": {},
5|system  |       "headers": {
5|system  |         "connection": "keep-alive",
5|system  |         "cache-control": "max-age=0",
5|system  |         "upgrade-insecure-requests": "1",
5|system  |         "user-agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36",
5|system  |         "accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
5|system  |         "sec-fetch-site": "same-origin",
5|system  |         "sec-fetch-mode": "navigate",
5|system  |         "sec-fetch-user": "?1",
5|system  |         "sec-fetch-dest": "document",
5|system  |         "sec-ch-ua": "\"Not A(Brand\";v=\"8\", \"Chromium\";v=\"132\", \"Google Chrome\";v=\"132\"",
5|system  |         "sec-ch-ua-mobile": "?0",
5|system  |         "sec-ch-ua-platform": "\"macOS\"",
5|system  |         "referer": "http://localhost:8008/system/bill-runs/review/460a2180-34c7-46aa-b72d-dfdb5b6c5472",
5|system  |         "accept-encoding": "gzip, deflate, br, zstd",
5|system  |         "accept-language": "en-GB,en;q=0.9,en-US;q=0.8",
5|system  |         "cookie": "imagine_a_long_string_made_up_of_a_mish_mash_of_letters_and_numbers_because_it_is_encrypted",
5|system  |         "x-forwarded-for": "172.18.0.1",
5|system  |         "x-forwarded-port": "57172",
5|system  |         "x-forwarded-proto": "http",
5|system  |         "x-forwarded-host": "localhost:8008",
5|system  |         "host": "localhost:8013"
5|system  |       },
5|system  |       "remoteAddress": "127.0.0.1",
5|system  |       "remotePort": 56298
5|system  |     }
5|system  |     res: {
5|system  |       "statusCode": 200,
5|system  |       "headers": {
5|system  |         "strict-transport-security": "max-age=15768000",
5|system  |         "x-frame-options": "DENY",
5|system  |         "x-xss-protection": "0",
5|system  |         "x-download-options": "noopen",
5|system  |         "x-content-type-options": "nosniff",
5|system  |         "cache-control": "no-cache",
5|system  |         "set-cookie": [
5|system  |           "wrlsSession=Fe26.imagine_a_long_string_made_up_of_a_mish_mash_of_letters_and_numbers_because_it_is_encrypted; Secure; HttpOnly; SameSite=Lax; Path=/"
5|system  |         ],
5|system  |         "content-type": "text/html; charset=utf-8",
5|system  |         "vary": "accept-encoding",
5|system  |         "content-encoding": "gzip"
5|system  |       }
5|system  |     }
5|system  |     responseTime: 104
```

However, from our experience of handling issues all we look at is

- `req:` - the ID (can be handy to trace transactions), the method, and the URL
- `res:` - the status code (did it succeed or error)

The rest is pure noise. On the other hand, there is some additional data that could be handy to see, for example, the payload on `POST` requests.

This change updates our config for [Hapi-pino](https://github.com/hapijs/hapi-pino) to to tell it to add the following to the logs

- the payload
- any query params
- any path params

It also implements our own serializers, which take the one returned by [pino-std-serializers](https://github.com/pinojs/pino-std-serializers) and transform it to only include the properties we care about. With these changes our log output now looks like this.

```text
5|system  | [16:33:17.125] INFO (1333): [response] post /bill-runs/review/460a2180-34c7-46aa-b72d-dfdb5b6c5472 302 (58ms)
5|system  |     req: {
5|system  |       "id": "1737909197067:9bc56d13c48b:1333:m6du9e83:10000",
5|system  |       "method": "get",
5|system  |       "url": "/bill-runs/review/460a2180-34c7-46aa-b72d-dfdb5b6c5472",
5|system  |       "query": {}
5|system  |     }
5|system  |     payload: {
5|system  |       "filterIssues": "aggregate-factor",
5|system  |       "filterLicenceStatus": "review"
5|system  |     }
5|system  |     queryParams: {}
5|system  |     pathParams: {
5|system  |       "billRunId": "460a2180-34c7-46aa-b72d-dfdb5b6c5472"
5|system  |     }
5|system  |     res: {
5|system  |       "statusCode": 302
5|system  |     }
5|system  |     responseTime: 58
5|system  | [16:33:17.235] INFO (1333): [response] get /bill-runs/review/460a2180-34c7-46aa-b72d-dfdb5b6c5472 200 (99ms)
5|system  |     req: {
5|system  |       "id": "1737909197135:9bc56d13c48b:1333:m6du9e83:10001",
5|system  |       "method": "get",
5|system  |       "url": "/bill-runs/review/460a2180-34c7-46aa-b72d-dfdb5b6c5472",
5|system  |       "query": {}
5|system  |     }
5|system  |     queryParams: {}
5|system  |     pathParams: {
5|system  |       "billRunId": "460a2180-34c7-46aa-b72d-dfdb5b6c5472"
5|system  |     }
5|system  |     res: {
5|system  |       "statusCode": 200
5|system  |     }
5|system  |     responseTime: 99
```
@Cruikshanks Cruikshanks added the housekeeping Refactoring, tidying up or other work which supports the project label Jan 26, 2025
@Cruikshanks Cruikshanks self-assigned this Jan 26, 2025
@Cruikshanks Cruikshanks marked this pull request as ready for review January 26, 2025 16:52
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.

@Cruikshanks Cruikshanks merged commit 97bdcb8 into main Jan 27, 2025
7 checks passed
@Cruikshanks Cruikshanks deleted the reduce-log-detail branch January 27, 2025 10:26
Cruikshanks added a commit to DEFRA/water-abstraction-ui that referenced this pull request Jan 27, 2025
We've completed a [number of changes to our logging](https://github.com/DEFRA/water-abstraction-team/issues?q=is%3Aissue%20state%3Aclosed%20log) in the time we have been on the project.

Generally, we 'go to the logs' when an issue has been reported in `production`, and we need to figure out what has happened.

Therefore, we constantly balance, ensuring we have all the necessary information while excluding noise.

We recently [made a change to water-abstraction-system](DEFRA/water-abstraction-system#1655) to reduce the noise in our logs via custom serializers (check it out for more details).

This change makes the same change to the logging in this app.
Cruikshanks added a commit to DEFRA/water-abstraction-import that referenced this pull request Jan 27, 2025
We've completed a [number of changes to our logging](https://github.com/DEFRA/water-abstraction-team/issues?q=is%3Aissue%20state%3Aclosed%20log) in the time we have been on the project.

Generally, we 'go to the logs' when an issue has been reported in `production`, and we need to figure out what has happened.

Therefore, we constantly balance, ensuring we have all the necessary information while excluding noise.

We recently [made a change to water-abstraction-system](DEFRA/water-abstraction-system#1655) to reduce the noise in our logs via custom serializers (check it out for more details).

This change makes the same change to the logging in this app.
Cruikshanks added a commit to DEFRA/water-abstraction-permit-repository that referenced this pull request Jan 27, 2025
We've completed a [number of changes to our logging](https://github.com/DEFRA/water-abstraction-team/issues?q=is%3Aissue%20state%3Aclosed%20log) in the time we have been on the project.

Generally, we 'go to the logs' when an issue has been reported in `production`, and we need to figure out what has happened.

Therefore, we constantly balance, ensuring we have all the necessary information while excluding noise.

We recently [made a change to water-abstraction-system](DEFRA/water-abstraction-system#1655) to reduce the noise in our logs via custom serializers (check it out for more details).

This change makes the same change to the logging in this app.
Cruikshanks added a commit to DEFRA/water-abstraction-returns that referenced this pull request Jan 27, 2025
We've completed a [number of changes to our logging](https://github.com/DEFRA/water-abstraction-team/issues?q=is%3Aissue%20state%3Aclosed%20log) in the time we have been on the project.

Generally, we 'go to the logs' when an issue has been reported in `production`, and we need to figure out what has happened.

Therefore, we constantly balance, ensuring we have all the necessary information while excluding noise.

We recently [made a change to water-abstraction-system](DEFRA/water-abstraction-system#1655) to reduce the noise in our logs via custom serializers (check it out for more details).

This change makes the same change to the logging in this app.
Cruikshanks added a commit to DEFRA/water-abstraction-tactical-crm that referenced this pull request Jan 27, 2025
We've completed a [number of changes to our logging](https://github.com/DEFRA/water-abstraction-team/issues?q=is%3Aissue%20state%3Aclosed%20log) in the time we have been on the project.

Generally, we 'go to the logs' when an issue has been reported in `production`, and we need to figure out what has happened.

Therefore, we constantly balance, ensuring we have all the necessary information while excluding noise.

We recently [made a change to water-abstraction-system](DEFRA/water-abstraction-system#1655) to reduce the noise in our logs via custom serializers (check it out for more details).

This change makes the same change to the logging in this app.
Cruikshanks added a commit to DEFRA/water-abstraction-tactical-idm that referenced this pull request Jan 27, 2025
We've completed a [number of changes to our logging](https://github.com/DEFRA/water-abstraction-team/issues?q=is%3Aissue%20state%3Aclosed%20log) in the time we have been on the project.

Generally, we 'go to the logs' when an issue has been reported in `production`, and we need to figure out what has happened.

Therefore, we constantly balance, ensuring we have all the necessary information while excluding noise.

We recently [made a change to water-abstraction-system](DEFRA/water-abstraction-system#1655) to reduce the noise in our logs via custom serializers (check it out for more details).

This change makes the same change to the logging in this app.
Cruikshanks added a commit to DEFRA/water-abstraction-import that referenced this pull request Jan 27, 2025
We've completed a [number of changes to our logging](https://github.com/DEFRA/water-abstraction-team/issues?q=is%3Aissue%20state%3Aclosed%20log) in the time we have been on the project.

Generally, we 'go to the logs' when an issue has been reported in `production`, and we need to figure out what has happened.

Therefore, we constantly balance, ensuring we have all the necessary information while excluding noise.

We recently [made a change to water-abstraction-system](DEFRA/water-abstraction-system#1655) to reduce the noise in our logs via custom serializers (check it out for more details).

This change makes the same change to the logging in this app.
Cruikshanks added a commit to DEFRA/water-abstraction-permit-repository that referenced this pull request Jan 27, 2025
We've completed a [number of changes to our logging](https://github.com/DEFRA/water-abstraction-team/issues?q=is%3Aissue%20state%3Aclosed%20log) in the time we have been on the project.

Generally, we 'go to the logs' when an issue has been reported in `production`, and we need to figure out what has happened.

Therefore, we constantly balance, ensuring we have all the necessary information while excluding noise.

We recently [made a change to water-abstraction-system](DEFRA/water-abstraction-system#1655) to reduce the noise in our logs via custom serializers (check it out for more details).

This change makes the same change to the logging in this app.
Cruikshanks added a commit to DEFRA/water-abstraction-service that referenced this pull request Jan 27, 2025
We've completed a [number of changes to our logging](https://github.com/DEFRA/water-abstraction-team/issues?q=is%3Aissue%20state%3Aclosed%20log) in the time we have been on the project.

Generally, we 'go to the logs' when an issue has been reported in `production`, and we need to figure out what has happened.

Therefore, we constantly balance, ensuring we have all the necessary information while excluding noise.

We recently [made a change to water-abstraction-system](DEFRA/water-abstraction-system#1655) to reduce the noise in our logs via custom serializers (check it out for more details).

This change makes the same change to the logging in this app.
Cruikshanks added a commit to DEFRA/water-abstraction-returns that referenced this pull request Jan 27, 2025
We've completed a [number of changes to our logging](https://github.com/DEFRA/water-abstraction-team/issues?q=is%3Aissue%20state%3Aclosed%20log) in the time we have been on the project.

Generally, we 'go to the logs' when an issue has been reported in `production`, and we need to figure out what has happened.

Therefore, we constantly balance, ensuring we have all the necessary information while excluding noise.

We recently [made a change to water-abstraction-system](DEFRA/water-abstraction-system#1655) to reduce the noise in our logs via custom serializers (check it out for more details).

This change makes the same change to the logging in this app.
Cruikshanks added a commit to DEFRA/water-abstraction-tactical-crm that referenced this pull request Jan 27, 2025
We've completed a [number of changes to our logging](https://github.com/DEFRA/water-abstraction-team/issues?q=is%3Aissue%20state%3Aclosed%20log) in the time we have been on the project.

Generally, we 'go to the logs' when an issue has been reported in `production`, and we need to figure out what has happened.

Therefore, we constantly balance, ensuring we have all the necessary information while excluding noise.

We recently [made a change to water-abstraction-system](DEFRA/water-abstraction-system#1655) to reduce the noise in our logs via custom serializers (check it out for more details).

This change makes the same change to the logging in this app.
Cruikshanks added a commit to DEFRA/water-abstraction-ui that referenced this pull request Jan 27, 2025
We've completed a [number of changes to our logging](https://github.com/DEFRA/water-abstraction-team/issues?q=is%3Aissue%20state%3Aclosed%20log) in the time we have been on the project.

Generally, we 'go to the logs' when an issue has been reported in `production`, and we need to figure out what has happened.

Therefore, we constantly balance, ensuring we have all the necessary information while excluding noise.

We recently [made a change to water-abstraction-system](DEFRA/water-abstraction-system#1655) to reduce the noise in our logs via custom serializers (check it out for more details).

This change makes the same change to the logging in this app.
Cruikshanks added a commit to DEFRA/water-abstraction-tactical-idm that referenced this pull request Jan 27, 2025
We've completed a [number of changes to our logging](https://github.com/DEFRA/water-abstraction-team/issues?q=is%3Aissue%20state%3Aclosed%20log) in the time we have been on the project.

Generally, we 'go to the logs' when an issue has been reported in `production`, and we need to figure out what has happened.

Therefore, we constantly balance, ensuring we have all the necessary information while excluding noise.

We recently [made a change to water-abstraction-system](DEFRA/water-abstraction-system#1655) to reduce the noise in our logs via custom serializers (check it out for more details).

This change makes the same change to the logging in this app.
Cruikshanks added a commit to DEFRA/water-abstraction-service that referenced this pull request Jan 27, 2025
We've completed a [number of changes to our logging](https://github.com/DEFRA/water-abstraction-team/issues?q=is%3Aissue%20state%3Aclosed%20log) in the time we have been on the project.

Generally, we 'go to the logs' when an issue has been reported in `production`, and we need to figure out what has happened.

Therefore, we constantly balance, ensuring we have all the necessary information while excluding noise.

We recently [made a change to water-abstraction-system](DEFRA/water-abstraction-system#1655) to reduce the noise in our logs via custom serializers (check it out for more details).

This change makes the same change to the logging in this app.
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