Skip to content

Commit

Permalink
Include less data in request logging
Browse files Browse the repository at this point in the history
This fixes two problems:

1. When required, the username is added to the request log just by
   accessing the `session` and not `current_user`, because the latter
   triggers the `user_loader`, which causes gathering every user
   information from the pycroft API.
2. Even more radically, we stop adding any extra information for
   `/static` endpoints, entirely.  Information like the IP is
   necessary for functional debugging (because it may be used as a
   substitute to the session for identifying the user, e.g. when using
   the traffic API), but completely pointless here.

Fixes #439
  • Loading branch information
lukasjuhrich committed Jun 11, 2022
1 parent 001b36c commit e47b1d9
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions sipa/blueprints/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,22 @@

@bp_generic.before_app_request
def log_request():
method = request.method
path = request.path
if path.startswith('/static'):
# We don't need extra information for troubleshooting in this case.
extra = {}
else:
extra = {'tags': {
# don't use `current_user` here, as this triggers the user loader,
# and consequently a call to the pycroft API.
# this is mostly unnecessary.
'user': session.get('_user_id', '<anonymous>'),
'ip': request.remote_addr
}}

logging.getLogger(__name__ + '.http').debug(
'Incoming request: %s %s', request.method, request.path,
extra={'tags': {'user': get_user_name(current_user),
'ip': request.remote_addr}}
'Incoming request: %s %s', method, path, extra=extra,
)


Expand Down

0 comments on commit e47b1d9

Please sign in to comment.