Univention Bugzilla – Bug 55186
[UDM REST API] Add correlation/request ID header to responses and log
Last modified: 2024-01-09 19:59:08 CET
UCS and UCS@school are being deployed in systems of growing complexity. Debuggung problems in those systems is becoming increasingly difficult, as more and more decoupled systems are interacting in an asynchronously way. The support (and also development) is having an increasingly hard time debugging request chains. A Correlation ID is a unique, randomly generated identifier value that is added to every request and response. In a microservice architecture, the initial Correlation ID is passed to each sub-processes. If a sub-system also makes sub-requests, it will also pass the Correlation ID to those systems. Debugging or tracing requests becomes much easier, as it is possible to search all logs for the same Correlation ID. The UDM REST API is used both directly and indirectly by multiple UCS@school REST APIs. When those APIs issue requests to the UDM REST API, they (will) emit a "X-Request-ID" HTTP header (name is configurable). (The value is a uuid4() string.) The UDM REST API should a) return the received header in its response headers. b) log the header (shorted to ~10 chars) in its log file.
Example in the BFF-Users app: ------------------------------------------------------------------------------- curl -X 'GET' \ 'http://10.207.110.216/ucsschool/bff-users/v1/users/detail/demo_student' \ -H 'accept: application/json' \ -H 'Authorization: Bearer eyJh...' ------------------------------------------------------------------------------- Response headers: access-control-expose-headers: X-Request-ID x-request-id: 4c2b138f0bdd4dce8956199703613072 ... ------------------------------------------------------------------------------- tail /var/log/univention/ucsschool-bff-users/http.log 2022-09-11 09:18:49 INFO [70][4c2b138f0b] h11_impl.send:477 172.17.42.1:56876 - "GET /users/detail/demo_student HTTP/1.1" 200 -------------------------------------------------------------------------------
Interesting pages I found regarding tornado and correlation IDs: * https://github.com/tornadoweb/tornado/issues/2216 * https://divak-tornado.readthedocs.io/en/latest/users-guide.html
The UDM REST API now accepts a uuid4 formatted `X-Request-Id` http request header and uses that in log messages for access-log and errors. The header value is send back as `X-Request-Id` response header. If no request header is set a uuid4 is generated. As UDM uses the C implementation of univention-debug we cannot prefix UDM log messages with the ID. This will be outsourced into Bug #55324. univention-directory-manager-rest.yaml 13f06d034562 | feat(udm-rest): set X-Request-Id header for traceability univention-directory-manager-rest (10.0.4-5) 13f06d034562 | feat(udm-rest): set X-Request-Id header for traceability 05375c40a0e5 | fix(udm-rest-client): prepare to receive HTTP 202 Accepted when moving objects c550ef90d6bf | chore(udm-rest): use async builtin functions b2e11e45c24a | fix(udm-rest): fix translation of gettext string 51591c9ad2d0 | style(udm-rest): pyupgrade --keep-percent-format --py37-plus
Verified: * The response header contain x-request-id * Advisory * ucs-test-udm-rest
<https://errata.software-univention.de/#/?erratum=5.0x466>