Repository navigation
This release adds Connexion 3 AsyncApp support and an opt-in way to read the request body in FastAPI, and fixes a few long-standing logging bugs. There's one behaviour change for Flask and Connexion apps that's worth reading before you upgrade, see "Upgrading" below.
pip install json-logging==1.7.0
Added
- Connexion 3
AsyncAppsupport.init_connexion()plusinit_request_instrument(app)now work with anAsyncApp, without Flask. Callinit_request_instrument(app)before the app starts. (#148, fixes #96) - FastAPI:
init_request_instrument(..., read_request_body=True)reads the body before the handler runs and puts it onrequest.state.json_logging_request_body, so a custom request formatter can use it. It's off by default, the body is never logged automatically, and it needs Starlette 0.28 or newer. (#146, fixes #84)
Changed
- With JSON logging enabled, unhandled exceptions from Flask and Connexion apps are now one JSON record with
levelandexc_infoinstead of a plain multi-line traceback.init_*()now converts handlers already attached to the root logger, andinit_request_instrument(app)convertsflask.logging.default_handler. (#147)
Fixed
- Records logged with
stack_info=Truenow keep the stack in astack_infofield. (#153, fixes #150) - An empty correlation ID header is treated as missing, so the next header is tried or an ID is generated when that's enabled. (#152, fixes #149)
get_request_logger()raises the documentedRuntimeErrorinstead ofAttributeErrorwhen called beforeinit_request_instrument(). (#139)- Request lookup no longer fails with
RuntimeError: dictionary changed size during iterationunder tracers and debuggers. (#120, fixes #89)
Upgrading
If you attach a root logger handler with your own formatter before calling init_*(), it will emit JSON after this upgrade. To keep a plain-text handler, add it after initialisation with an explicit logging.Formatter. If your log parsers or alerts match on the old multi-line Flask tracebacks, check them before rolling this out.
Default output is otherwise unchanged, apart from the new stack_info field (only for records that ask for it) and the empty-header change above.
Known limitations with Connexion 3 AsyncApp
- The request log is written after the app call returns, so if a background task raises after the response is sent, the request log can be missing.
response_time_msincludes background task time.- Instrumenting an
AsyncAppturns off theuvicorn.accesslogger for the whole process. remote_useris-inAsyncApprequest logs.
Tested on Python 3.9 to 3.14. Full details are in the changelog.