Skip to content

[16.0] [ADD] fastapi_log #501

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

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from

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

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 see 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?


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.

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.

4 participants