Skip to content

Commit

Permalink
Merge branch 'dev' into fix-mailing-note
Browse files Browse the repository at this point in the history
  • Loading branch information
i-oden authored Mar 1, 2022
2 parents 5de9a5c + 938751b commit d66fe74
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,4 @@ Please add a _short_ line describing the PR you make, if the PR implements a spe
* Add support for getting IPs from X-Forwarded-For ([#952](https://github.com/ScilifelabDataCentre/dds_web/pull/952))
* Relax requirements for usernames (wider length range, `.` and `-`) ([#943](https://github.com/ScilifelabDataCentre/dds_web/pull/943))
* Fix logic for notification about sent email ([#963])(https://github.com/ScilifelabDataCentre/dds_web/pull/963))
* Extended the `dds_web.api.dds_decorators.logging_bind_request` decorator to catch all not yet caught exceptions and make sure they will be logged ([#958](https://github.com/ScilifelabDataCentre/dds_web/pull/958)).
29 changes: 20 additions & 9 deletions dds_web/api/dds_decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
BucketNotFoundError,
DatabaseError,
DDSArgumentError,
LoggedHTTPException,
NoSuchUserError,
AccessDeniedError,
MissingJsonError,
Expand Down Expand Up @@ -155,15 +156,25 @@ def wrapper_logging_bind_request(*args, **kwargs):
project=flask.request.args.get("project") if flask.request.args else None,
user=get_username_or_request_ip(),
):
value = func(*args, **kwargs)

if hasattr(value, "status"):
structlog.threadlocal.bind_threadlocal(response=value.status)

action_logger.info(f"{flask.request.endpoint}.{func.__name__}")

# make sure the threadlocal state is pruned after the log was written.
structlog.threadlocal.clear_threadlocal()
return value
try:
value = func(*args, **kwargs)

if hasattr(value, "status"):
structlog.threadlocal.bind_threadlocal(response=value.status)

action_logger.info(f"{flask.request.endpoint}.{func.__name__}")
# make sure the threadlocal state is pruned after the log was written.
structlog.threadlocal.clear_threadlocal()
return value

except Exception as err:
if not isinstance(err, LoggedHTTPException):
# HTTPExceptions are already logged as warnings, no need to log twice.
action_logger.exception(
f"Uncaught exception in {flask.request.endpoint}.{func.__name__}",
stack_info=True,
)
raise

return wrapper_logging_bind_request

0 comments on commit d66fe74

Please sign in to comment.