fix: keep access logs when the request peer is gone - #35
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #34.
json_logging1.5.1 dereferences Starlette's optionalRequest.clientunguarded, so any request whose peer socket is already gone (kubelet resetting a timed-out readiness probe) loses its access-log line to a formatter traceback on stderr.The issue suggested passing a custom extractor to
init_request_instrument, but that function has no such parameter: the extractor class comes from json_logging's framework registry and is frozen into theRequestUtilsingleton byinit_fastapi. Sorequest_logging.pysubclassesFastAPIRequestInfoExtractorand re-registers it viaregister_framework_support, called immediately beforeinit_fastapi. Once upstream ships bobbui/json-logging-python#116 the module can be deleted.Dropping
init_request_instrument(the issue's other option) was rejected: it removes every access log, a larger behaviour change than the bug, and an upstream release would not undo it.Covered by unit tests on both accessors and the registry swap, plus a subprocess test that drives
/healthwithscope["client"] = Noneand asserts no logging error on stderr; it fails without the fix. Subprocess becausejson_logging.init_*mutates process-wide logging state irreversibly.