Skip to content
This repository has been archived by the owner on May 3, 2024. It is now read-only.

fix(configureRequestLog): use default when configured with undefined #1029

Merged
merged 4 commits into from
Jun 21, 2023

Conversation

JAdshead
Copy link
Contributor

@JAdshead JAdshead commented Jun 16, 2023

Description

if configureRequestLog is not provided by root module, request logs are not being logged.

Motivation and Context

re enable request logs

How Has This Been Tested?

Test suite and locally

Types of Changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation (adding or updating documentation)
  • Dependency update
  • Security update

Checklist:

  • My change requires a change to the documentation and I have updated the documentation accordingly.
  • These changes should be applied to a maintenance branch.
  • This change requires cross browser checks.
  • Performance tests should be ran against the server prior to merging.
  • This change impacts caching for client browsers.
  • This change impacts HTTP headers.
  • This change adds additional environment variable requirements for One App users.
  • I have added the Apache 2.0 license header to any new files created.

What is the Impact to Developers Using One App?

@github-actions
Copy link
Contributor

github-actions bot commented Jun 16, 2023

Size Change: 0 B

Total Size: 687 kB

ℹ️ View Unchanged
Filename Size
./build/app/app.js 164 kB
./build/app/app~vendors.js 389 kB
./build/app/runtime.js 7.07 kB
./build/app/service-worker-client.js 7.26 kB
./build/app/vendors.js 120 kB

compressed-size-action

@Matthew-Mallimo Matthew-Mallimo requested a review from a team June 19, 2023 13:42

logClientRequest(request, reply);
} catch (error) {
console.error(error);
Copy link
Member

Choose a reason for hiding this comment

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

shouldn't we use the logger here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this does use it. console is monkey patched to use the logger https://github.com/americanexpress/one-app/blob/main/src/server/utils/logging/setup.js#L28

endTimer(request, $RequestFullDuration);

logClientRequest(request, reply);
try {
Copy link
Member

Choose a reason for hiding this comment

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

why is the try/catch needed here? it catches the error, logs it, and throws it, meaning that we only need to log it right? Fastify handles uncaught errors for us (https://www.fastify.io/docs/latest/Reference/Errors/) so no need for a try/catch

Copy link
Contributor Author

Choose a reason for hiding this comment

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

not for onResponse hooks, this currently fails silently

@@ -137,7 +138,7 @@ const logClientRequest = (request, reply) => {
logger.info(configuredLog);
};

export const setConfigureRequestLog = (newConfigureRequestLog) => {
export const setConfigureRequestLog = (newConfigureRequestLog = passThrough) => {
Copy link
Member

Choose a reason for hiding this comment

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

why would somebody call setConfigureRequestLog without passing an argument?

Copy link
Contributor Author

@JAdshead JAdshead Jun 20, 2023

Choose a reason for hiding this comment

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

why should this be allowed to fail when called without an argument ? It's called every time during onModule load. This is also how its handled in 5.x.x and should not have been removed.

Copy link
Member

Choose a reason for hiding this comment

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

because it shouldn't be called without an argument

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It shouldn't but it is. I don't see the issue having a default to improve resiliency

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

I won't block it but it's a bad practice. The function by starting with the word set lets the developer know that it "sets" something, and the data will always be expected (you cannot set something with no data, otherwise would be like a reset). That's the reason why all functions, like the write from fs will throw an error if data is not provided. If we want a set to be "safe" I would rename it to something like safeSetConfigureRequestLog, but, still, ideally, the user should always pass data

@JAdshead JAdshead requested review from giulianok and a team June 20, 2023 21:25
@JAdshead JAdshead merged commit 02eda87 into main Jun 21, 2023
@JAdshead JAdshead deleted the fix/set-configure-request-log branch June 21, 2023 15:18
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants