Skip to content

Commit

Permalink
RequestIdContextAccessLogger: do not fail when request_id is not set
Browse files Browse the repository at this point in the history
  • Loading branch information
messa authored May 2, 2024
1 parent 6300be6 commit 39cddca
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion aiohttp_request_id_logging/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,16 @@ def new_factory(*args, **kwargs):
class RequestIdContextAccessLogger (_AccessLogger):

def log(self, request, response, time):
token = request_id.set(request['request_id'])
try:
request_id_value = request['request_id']
except KeyError:
# If there is no request['request_id'], for example when an error
# occurs in a middleware, fall back to just logging without setting
# the request_id context variable.
super().log(request, response, time)
return

token = request_id.set(request_id_value)
try:
super().log(request, response, time)
finally:
Expand Down

0 comments on commit 39cddca

Please sign in to comment.