Skip to content

Conversation

@paradoxxxzero
Copy link
Contributor

@paradoxxxzero paradoxxxzero commented Feb 25, 2025

This module allows an endpoint to activate full request logging in a database model.

It is useful to debug production issues or to monitor the usage of a specific endpoint.

This is not a migration of rest_log, this module aims to be simpler, at least in the first iterations.

This PR depends on #500

@simahawk
Copy link
Contributor

Thanks for working on this. I wanted to do it since a while 😅

Early feedback...

The way I was planning to handle this was to have a base module to collect any kind of "request/response log".
This can be used by fastapi, base_rest, edi framework, endpoints and any custom implementation of request/response feature.

Would you consider splitting this part to a module like request_log or something like that?

@paradoxxxzero
Copy link
Contributor Author

@simahawk for now I don't want to overengineer this module. But feel free to split it when done. As a side note about that, is there any advantage to have all heterogeneous logs in the same model/views? Because aside of that, the amount of factored code would be low.

@SirPyTech
Copy link

Hi @paradoxxxzero, thanks for this PR!
Are you still working on this?

@paradoxxxzero paradoxxxzero marked this pull request as ready for review April 17, 2025 07:12
@paradoxxxzero
Copy link
Contributor Author

Hello, no we have it deployed, I just forgot to remove the draft status, thanks.

Copy link
Contributor

@PicchiSeba PicchiSeba left a comment

Choose a reason for hiding this comment

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

Code review

Comment on lines +25 to +29
fastapi_endpoint = (
self.request.env["fastapi.endpoint"]
.sudo()
.search([("root_path", "=", root_path)])
)
Copy link
Contributor

@PicchiSeba PicchiSeba Apr 24, 2025

Choose a reason for hiding this comment

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

question: what do you think about calling the get_uid method of fastapi.endpoint?

This way, if we need to override the method, the same endpoint will be matched

Copy link

@SirPyTech SirPyTech Apr 28, 2025

Choose a reason for hiding this comment

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

get_uid would return the user ID, could you please clarify how that could be used in this piece of code?

In akretion#8 I have included your PR #515 and used the new get_endpoint, is that what you meant?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah that's what I meant. Sorry for the confusion.


def _headers_to_dict(self, headers):
try:
return {key.lower(): value for key, value in headers.items()}
Copy link
Contributor

Choose a reason for hiding this comment

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

issue: we should redact sentitive headers

@property
def _log_call_header_strip(self):
return ("Cookie", "Api-Key")

for k in params.keys():
if k in BLACKLISTED_LOG_PARAMS:
params[k] = "<redacted>"

Choose a reason for hiding this comment

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

Right, added this too in akretion#8.

finally:
if not tools.config["test_enable"]:
try:
cr.commit() # pylint: disable=E8102
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you want to rollback the all the process if you encounter an error only with the cursor used for logging?

@sebastienbeau sebastienbeau added this to the 16.0 milestone Jun 3, 2025
@aleuffre
Copy link

aleuffre commented Jul 1, 2025

Hello @paradoxxxzero
Could I ask you to take a look at akretion#8 , we've done a lot of work on it and think it brings several useful improvements.

Thank you!

@Kev-Roche Kev-Roche force-pushed the 16.0-add-fastapi_log branch from cac2381 to 16fa971 Compare July 15, 2025 08:33
@paradoxxxzero
Copy link
Contributor Author

Superseeded by #554

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.

7 participants