Bug 56970 - [UDM REST API] prefix UDM log messages with request ID
[UDM REST API] prefix UDM log messages with request ID
Status: CLOSED FIXED
Product: UCS
Classification: Unclassified
Component: UDM - REST API
UCS 5.0
Other Linux
: P5 normal (vote)
: UCS 5.0-6-errata
Assigned To: Florian Best
Marius Meschter
https://git.knut.univention.de/univen...
:
Depends on: 55186 55324
Blocks:
  Show dependency treegraph
 
Reported: 2024-01-09 19:59 CET by Florian Best
Modified: 2024-03-05 09:53 CET (History)
2 users (show)

See Also:
What kind of report is it?: Feature Request
What type of bug is this?: ---
Who will be affected by this bug?: ---
How will those affected feel about the bug?: ---
User Pain:
Enterprise Customer affected?:
School Customer affected?:
ISV affected?:
Waiting Support:
Flags outvoted (downgraded) after PO Review:
Ticket number:
Bug group (optional):
Max CVSS v3 score:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Florian Best univentionstaff 2024-01-09 19:59:08 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 +++
Comment 2 Florian Best univentionstaff 2024-02-12 22:29:53 CET
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
Comment 3 Daniel Tröder univentionstaff 2024-02-13 08:57:07 CET
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.
Comment 4 Florian Best univentionstaff 2024-02-13 11:26:11 CET
(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
Comment 5 Marius Meschter univentionstaff 2024-02-13 13:31:46 CET
QA:
- YAML/Changelog: OK
- loglines of UDM prefixed with request-id: OK