Univention Bugzilla – Bug 56970
[UDM REST API] prefix UDM log messages with request ID
Last modified: 2024-03-05 09:53:26 CET
The changes for UDM REST API will be split into this bug, so that the original bug adds the required univention-debug handler for the python-logging module. This bug has to create a logging filter or adapter which adds the request-ID to all log messages using contextvars. +++ This bug was initially created as a clone of Bug #55324 +++ In Bug #55186 as request ID has been added to the UDM REST API. The request ID is logged but not in the underlying UDM log messages. UDM could use python-logging with a special backwards compatible univention.debug handler. A python-logging filter could insert the request ID. The UDM REST API should store a global context variable so that asynchronous operations log the correct request ID. https://peps.python.org/pep-0567/ https://docs.python.org/3/library/contextvars.html +++ This bug was initially created as a clone of Bug #55186 +++
PoC in Tornado: https://quanttype.net/posts/2020-02-05-request-id-logging.html Implemented that in: https://git.knut.univention.de/univention/ucs/-/merge_requests/1018
UDM and univention.uldap have been changed so that the use of univention.debug is replaced with logging. We still initialize univention.debug via the univention.logging module, so that third-party UDM modules can still log via univention.debug. The log message in UDM REST API can not be prefixed with the shortened X-Request-ID by setting the UCR variable directory/manager/rest/debug/prefix-with-request-id to true. univention-directory-manager-modules (15.0.25-5) c3f38de1c9f6 | refactor(udm): replace use of univention.debug with logging interface Since Bug #55324 we introduced a logging handler, which logs to univention.debug. We can therefor use the logging interface in UDM now. This is a prerequisite to be able to prefix UDM log messages with a request ID in the logs of UDM REST API. univention-directory-manager-rest (10.0.7-7) 8f09e61b14ba | feat(udm-rest): prefix log lines with context id of request Add a logging filter which prefixes all log entries with the context ID of the request. We use a global contextvar which is bound the async context. univention-python.yaml 58250d428ae7 | refactor(uldap): replace use of univention.debug with logging interface univention-python (13.0.5-2) 58250d428ae7 | refactor(uldap): replace use of univention.debug with logging interface univention-directory-manager-rest.yaml 8f09e61b14ba | feat(udm-rest): prefix log lines with context id of request univention-directory-manager-modules.yaml c3f38de1c9f6 | refactor(udm): replace use of univention.debug with logging interface 3f5b58680f28 | ci(pre-commit): partly enable ruff logging checks
The default of UCRV directory/manager/rest/debug/prefix-with-request-id should be "true". Currently the UDM REST API does log a request ID by default. That is very useful when debugging, for example, Kelvin or Guardian -> UDM calls. Not only is that desired, but disabling it now is, IMHO a kind of regression.
(In reply to Daniel Tröder from comment #3) > The default of UCRV directory/manager/rest/debug/prefix-with-request-id > should be "true". > Currently the UDM REST API does log a request ID by default. > That is very useful when debugging, for example, Kelvin or Guardian -> UDM > calls. > Not only is that desired, but disabling it now is, IMHO a kind of regression. You are right, I set the default to True: univention-directory-manager-rest (10.0.7-8) f0a59e8533a0 | feat(udm-rest): set default for prefixing log messages to true
QA: - YAML/Changelog: OK - loglines of UDM prefixed with request-id: OK
<https://errata.software-univention.de/#/?erratum=5.0x957> <https://errata.software-univention.de/#/?erratum=5.0x958> <https://errata.software-univention.de/#/?erratum=5.0x959>